Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jqmgJ-0000DQ-BF for pgsql-general@arkaria.postgresql.org; Thu, 02 Jul 2020 00:02:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jqmgI-0008Jb-8i for pgsql-general@arkaria.postgresql.org; Thu, 02 Jul 2020 00:02:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jqmgI-0008JT-0h for pgsql-general@lists.postgresql.org; Thu, 02 Jul 2020 00:02:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jqmgF-0008Cp-Nj for pgsql-general@lists.postgresql.org; Thu, 02 Jul 2020 00:02:21 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 06202HtE815599; Wed, 1 Jul 2020 20:02:17 -0400 From: Tom Lane To: Anders Steinlein cc: pgsql-general@lists.postgresql.org Subject: Re: Different results from identical matviews In-reply-to: References: Comments: In-reply-to Anders Steinlein message dated "Thu, 02 Jul 2020 01:39:48 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <815597.1593648137.1@sss.pgh.pa.us> Date: Wed, 01 Jul 2020 20:02:17 -0400 Message-ID: <815598.1593648137@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Anders Steinlein writes: > We have a materialized view from which a customer reported some > confusing/invalid results, leading us to inspect the query and not finding > anything wrong. Running the query defining the matview manually, or > creating a new (identical) materialized view returns the correct result. > Obviously, we've done REFRESH MATERIALIZED VIEW just before doing the > comparison, and all runs are in the same schema. I suspect the query underlying the matviews is less deterministic than you think it is. I did not study that query in any detail, but just from a quick eyeball: the array_agg() calls with no attempt to enforce a particular aggregation order are concerning, and so is grouping by a citext column (where you'll get some case-folding of a common value, but who knows which). regards, tom lane