Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hmmtZ-0001to-Lx for pgsql-bugs@arkaria.postgresql.org; Sun, 14 Jul 2019 22:23:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hmmtY-00082u-62 for pgsql-bugs@arkaria.postgresql.org; Sun, 14 Jul 2019 22:23: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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hmmtX-0007zB-Su for pgsql-bugs@lists.postgresql.org; Sun, 14 Jul 2019 22:22: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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hmmtV-0003eK-48 for pgsql-bugs@lists.postgresql.org; Sun, 14 Jul 2019 22:22: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 x6EMMoFg025847; Sun, 14 Jul 2019 18:22:51 -0400 From: Tom Lane To: Manuel Rigger cc: PostgreSQL mailing lists , Tomas Vondra Subject: Re: SELECT with COLLATE results in segfault on trunk and 12 Beta 2 In-reply-to: References: Comments: In-reply-to Manuel Rigger message dated "Sun, 14 Jul 2019 23:30:26 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <25845.1563142970.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 14 Jul 2019 18:22:50 -0400 Message-ID: <25846.1563142970@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Manuel Rigger writes: > When executing the statements below, Postgres crashes: > CREATE TABLE t0(c0 BOOLEAN, c1 TEXT); > CREATE STATISTICS s1 ON c0, c1 FROM t0; > INSERT INTO t0(c0) VALUES (FALSE); > VACUUM ANALYZE t0; > SELECT * FROM t0 WHERE t0.c0 OR '' >=3D t0.c1 COLLATE "C"; -- unexpected= : segfault Backtrace shows #0 pg_detoast_datum_packed (datum=3D0x7f7f7f7f7f7f7f7f) at fmgr.c:1773 #1 0x00000000008a9b90 in text_ge (fcinfo=3D0x7ffc8cdbfd40) at varlena.c:1= 859 #2 0x00000000008cf307 in FunctionCall2Coll (flinfo=3D0x7ffc8cdbfe00, = collation=3D, arg1=3D, = arg2=3D) at fmgr.c:1162 #3 0x0000000000773db0 in mcv_get_match_bitmap (root=3D0x26b7bc8, = clauses=3D, keys=3D0x26b8b90, mcvlist=3D0x26b88f0= , = is_or=3Dtrue) at mcv.c:1661 #4 0x0000000000773ecb in mcv_get_match_bitmap (root=3D0x26b7bc8, = clauses=3D, keys=3D0x26b8b90, mcvlist=3D0x26b88f0= , = is_or=3Dfalse) at mcv.c:1744 #5 0x0000000000775d61 in mcv_clauselist_selectivity (root=3D0x26b7bc8, = stat=3D0x26b8b58, clauses=3D0x26b9008, varRelid=3D, = jointype=3D, sjinfo=3D, = rel=3D0x25a46a0, basesel=3D0x7ffc8cdc0038, totalsel=3D0x7ffc8cdc0030) at mcv.c:1876 I think this is another variant of the mcv_get_match_bitmap issues that you and Andreas already reported, ie, that code isn't expecting to find anything but a bare Var or Const, so the CollateExpr node above the Var confuses it. It's possible that it'd be worth descending through CollateExpr nodes in the same way as for RelabelType nodes, and for more or less the same reason. regards, tom lane