Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fuky2-0004jj-36 for pgsql-general@arkaria.postgresql.org; Tue, 28 Aug 2018 20:52:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fuky0-0006AR-0w for pgsql-general@arkaria.postgresql.org; Tue, 28 Aug 2018 20:52:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fukxz-0006AK-PF for pgsql-general@lists.postgresql.org; Tue, 28 Aug 2018 20:51:59 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fukxv-0005A2-MX for pgsql-general@lists.postgresql.org; Tue, 28 Aug 2018 20:51:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w7SKppTW013074; Tue, 28 Aug 2018 16:51:51 -0400 From: Tom Lane To: Tim Clarke cc: pgsql-general@lists.postgresql.org Subject: Re: archive items not in correct section order In-reply-to: <87a088a1-667b-26cb-de58-ca89077d66c2@minerva-analytics.info> References: <2efc7f44-2820-6b86-6a45-b46bd32cc44d@minerva-analytics.info> <450.1535379741@sss.pgh.pa.us> <6a3a3c92-bd2e-df53-da3a-877cb41bc7e0@minerva-analytics.info> <87a088a1-667b-26cb-de58-ca89077d66c2@minerva-analytics.info> Comments: In-reply-to Tim Clarke message dated "Tue, 28 Aug 2018 20:39:05 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13072.1535489511.1@sss.pgh.pa.us> Date: Tue, 28 Aug 2018 16:51:51 -0400 Message-ID: <13073.1535489511@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Tim Clarke writes: > On 27/08/18 15:22, Tom Lane wrote: >> That's not supposed to happen. Can you create a test case, by any chance? > It wasn't the cross-tab/pivot, it was this materialized view: Hm, could I trouble you for a self-contained test case? I tried to flesh it out as attached, but I'm not seeing any error with this. So there must be some other moving part ... regards, tom lane drop schema rating cascade; drop schema r cascade; create schema rating; create table rating.cy (f1 int, cid int, ye int); create schema r; set search_path = r; create table c(id int); create table f(id int, cid int, ye int, ytext text); create table wb(cid int, fid int, prop float8); CREATE materialized VIEW r.b AS SELECT c.id, f.ytext, min(coalesce( (select case when wb.prop >= 0.333 then 4 when wb.prop >= 0.25 then 3 when wb.prop >= 0.15 then 2 when wb.prop >= 0.1 then 1 else 0 end FROM r.wb where wb.cid = c.id and wb.fid = f.id), 0)) as score FROM rating.cy, c, f WHERE c.id = f.cid AND f.cid = cy.cid AND f.ye = cy.ye GROUP BY 1, 2 LIMIT 1;