Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Ybw5v-0005EI-Mq for pgsql-bugs@arkaria.postgresql.org; Sat, 28 Mar 2015 19:08:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Ybw5u-0003tq-2D for pgsql-bugs@arkaria.postgresql.org; Sat, 28 Mar 2015 19:08:30 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Ybw5r-0003th-FH for pgsql-bugs@postgresql.org; Sat, 28 Mar 2015 19:08:27 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Ybw5j-0001Fh-0C for pgsql-bugs@postgresql.org; Sat, 28 Mar 2015 19:08:25 +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 t2SJ8Gsf014245; Sat, 28 Mar 2015 15:08:16 -0400 From: Tom Lane To: Jeff Davis cc: pgsql-bugs@postgresql.org Subject: Re: pg_get_constraintdef() doesn't always give an equal constraint In-reply-to: References: <19820.1427153553@sss.pgh.pa.us> Comments: In-reply-to Jeff Davis message dated "Fri, 27 Mar 2015 19:27:49 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <14169.1427569510.0@sss.pgh.pa.us> Date: Sat, 28 Mar 2015 15:08:16 -0400 Message-ID: <14244.1427569696@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14169.1427569510.1@sss.pgh.pa.us> Jeff Davis writes: > On Mon, Mar 23, 2015 at 7:32 PM, Tom Lane wrote: >> I don't see any simple way around that except to dump using the syntax >> '10.1'::double precision > There is a similar problem related to NUMERIC: > '1'::numeric is dumped as > 1::numeric > which introduces a cast as well. There's also a problem with negative > constants, because it introduces parenthesis instead of single quotes: > '-1'::numeric > is dumped as > (-1)::numeric Yeah. In general, this code was trying to produce something nice-looking and semantically equivalent, but not necessarily something that would re-parse as the exact same Const node. > This bug is pretty old and nobody has complained about it before. > Let's just figure out a good unambiguous representation of float and > numeric literals, and then backport it. Anyone who cares enough to fix > this issue can upgrade to the latest point release on the old version, > and then dump/reload. > For numeric, I think appending ".0" (if it's an integral value) is the > easiest, prettiest, and least-surprising. ... and wrong, because that would affect the dscale. I don't think we want this code editorializing on the printed format in any case. > For floats, we can either > use the single-quotes and type annotation, or we can come up with > something new like appending an "f" to the value. I cannot see back-porting anything as invasive as changing the lexer. Basically, I think we have to change ruleutils so that it quotes anything that wouldn't be seen as a simple integer or numeric constant by the lexer+grammar. The attached patch does this; the regression test changes illustrate what's going to happen to the output if we do this. Looking at the changes, I'm not 100% convinced we want to back-patch. As you say, nobody's complained of this problem before, and I'm worried that people will see the output changes as a bigger deal than the issue we're trying to fix. Thoughts? regards, tom lane (PS: I've not checked contrib or pl tests, so this patch may be incomplete as far as expected-output changes go.) ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="fix-ruleutils-const-dumping.patch"; charset="us-ascii" Content-ID: <14169.1427569510.2@sss.pgh.pa.us> Content-Description: fix-ruleutils-const-dumping.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/rule= utils.c index 28e1acf..4672cf5 100644 *** a/src/backend/utils/adt/ruleutils.c --- b/src/backend/utils/adt/ruleutils.c *************** *** 15,20 **** --- 15,21 ---- */ #include "postgres.h" =20=20 + #include #include #include =20=20 *************** get_const_expr(Const *constval, deparse_ *** 8018,8025 **** Oid typoutput; bool typIsVarlena; char *extval; ! bool isfloat =3D false; ! bool needlabel; =20=20 if (constval->constisnull) { --- 8019,8025 ---- Oid typoutput; bool typIsVarlena; char *extval; ! bool needlabel =3D false; =20=20 if (constval->constisnull) { *************** get_const_expr(Const *constval, deparse_ *** 8045,8084 **** =20=20 switch (constval->consttype) { - case INT2OID: case INT4OID: ! case INT8OID: ! case OIDOID: ! case FLOAT4OID: ! case FLOAT8OID: case NUMERICOID: { ! /* ! * These types are printed without quotes unless they contain ! * values that aren't accepted by the scanner unquoted (e.g., ! * 'NaN'). Note that strtod() and friends might accept NaN, ! * so we can't use that to test. ! * ! * In reality we only need to defend against infinity and NaN, ! * so we need not get too crazy about pattern matching here. ! * ! * There is a special-case gotcha: if the constant is signed, ! * we need to parenthesize it, else the parser might see a ! * leading plus/minus as binding less tightly than adjacent ! * operators --- particularly, the cast that we might attach ! * below. ! */ ! if (strspn(extval, "0123456789+-eE.") =3D=3D strlen(extval)) ! { ! if (extval[0] =3D=3D '+' || extval[0] =3D=3D '-') ! appendStringInfo(buf, "(%s)", extval); ! else ! appendStringInfoString(buf, extval); ! if (strcspn(extval, "eE.") !=3D strlen(extval)) ! isfloat =3D true; /* it looks like a float */ ! } ! else ! appendStringInfo(buf, "'%s'", extval); } break; =20=20 --- 8045,8086 ---- =20=20 switch (constval->consttype) { case INT4OID: !=20 ! /* ! * INT4 can be printed without any decoration, unless it is ! * negative; in that case print it as '-nnn'::integer to ensure ! * that the output will re-parse as a constant, not as a constant ! * plus operator. In most cases we could get away with printing ! * (-nnn) instead, because of the way that gram.y handles negative ! * literals; but that doesn't work for INT_MIN, and it doesn't ! * seem that much prettier anyway. ! */ ! if (extval[0] !=3D '-') ! appendStringInfoString(buf, extval); ! else ! { ! appendStringInfo(buf, "'%s'", extval); ! needlabel =3D true; /* we must attach a cast */ ! } ! break; !=20 case NUMERICOID: +=20 + /* + * NUMERIC can be printed without quotes if it looks like a float + * constant (not an integer, and not Infinity or NaN) and doesn't + * have a leading sign (for the same reason as for INT4). + */ + if (isdigit((unsigned char) extval[0]) && + strcspn(extval, "eE.") !=3D strlen(extval)) { ! appendStringInfoString(buf, extval); ! } ! else ! { ! appendStringInfo(buf, "'%s'", extval); ! needlabel =3D true; /* we must attach a cast */ } break; =20=20 *************** get_const_expr(Const *constval, deparse_ *** 8114,8131 **** switch (constval->consttype) { case BOOLOID: - case INT4OID: case UNKNOWNOID: /* These types can be left unlabeled */ needlabel =3D false; break; case NUMERICOID: =20=20 /* * Float-looking constants will be typed as numeric, but if * there's a specific typmod we need to show it. */ ! needlabel =3D !isfloat || (constval->consttypmod >=3D 0); break; default: needlabel =3D true; --- 8116,8135 ---- switch (constval->consttype) { case BOOLOID: case UNKNOWNOID: /* These types can be left unlabeled */ needlabel =3D false; break; + case INT4OID: + /* We determined above whether a label is needed */ + break; case NUMERICOID: =20=20 /* * Float-looking constants will be typed as numeric, but if * there's a specific typmod we need to show it. */ ! needlabel |=3D (constval->consttypmod >=3D 0); break; default: needlabel =3D true; diff --git a/src/test/regress/expected/equivclass.out b/src/test/regress/ex= pected/equivclass.out index dfae84e..0391b8e 100644 *** a/src/test/regress/expected/equivclass.out --- b/src/test/regress/expected/equivclass.out *************** set enable_mergejoin =3D off; *** 104,114 **** -- explain (costs off) select * from ec0 where ff =3D f1 and f1 =3D '42'::int8; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20 ! ---------------------------------- Index Scan using ec0_pkey on ec0 ! Index Cond: (ff =3D 42::bigint) ! Filter: (f1 =3D 42::bigint) (3 rows) =20=20 explain (costs off) --- 104,114 ---- -- explain (costs off) select * from ec0 where ff =3D f1 and f1 =3D '42'::int8; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20=20 ! ----------------------------------- Index Scan using ec0_pkey on ec0 ! Index Cond: (ff =3D '42'::bigint) ! Filter: (f1 =3D '42'::bigint) (3 rows) =20=20 explain (costs off) *************** explain (costs off) *** 139,150 **** =20=20 explain (costs off) select * from ec1, ec2 where ff =3D x1 and ff =3D '42'::int8; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! --------------------------------------------------------------- Nested Loop Join Filter: (ec1.ff =3D ec2.x1) -> Index Scan using ec1_pkey on ec1 ! Index Cond: ((ff =3D 42::bigint) AND (ff =3D 42::bigint)) -> Seq Scan on ec2 (5 rows) =20=20 --- 139,150 ---- =20=20 explain (costs off) select * from ec1, ec2 where ff =3D x1 and ff =3D '42'::int8; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! ------------------------------------------------------------------- Nested Loop Join Filter: (ec1.ff =3D ec2.x1) -> Index Scan using ec1_pkey on ec1 ! Index Cond: ((ff =3D '42'::bigint) AND (ff =3D '42'::bigint)) -> Seq Scan on ec2 (5 rows) =20=20 *************** explain (costs off) *** 161,174 **** =20=20 explain (costs off) select * from ec1, ec2 where ff =3D x1 and '42'::int8 =3D x1; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! ---------------------------------------- Nested Loop Join Filter: (ec1.ff =3D ec2.x1) -> Index Scan using ec1_pkey on ec1 ! Index Cond: (ff =3D 42::bigint) -> Seq Scan on ec2 ! Filter: (42::bigint =3D x1) (6 rows) =20=20 explain (costs off) --- 161,174 ---- =20=20 explain (costs off) select * from ec1, ec2 where ff =3D x1 and '42'::int8 =3D x1; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! ----------------------------------------- Nested Loop Join Filter: (ec1.ff =3D ec2.x1) -> Index Scan using ec1_pkey on ec1 ! Index Cond: (ff =3D '42'::bigint) -> Seq Scan on ec2 ! Filter: ('42'::bigint =3D x1) (6 rows) =20=20 explain (costs off) *************** explain (costs off) *** 210,216 **** ----------------------------------------------------- Nested Loop -> Index Scan using ec1_pkey on ec1 ! Index Cond: (ff =3D 42::bigint) -> Append -> Index Scan using ec1_expr2 on ec1 ec1_1 Index Cond: (((ff + 2) + 1) =3D ec1.f1) --- 210,216 ---- ----------------------------------------------------- Nested Loop -> Index Scan using ec1_pkey on ec1 ! Index Cond: (ff =3D '42'::bigint) -> Append -> Index Scan using ec1_expr2 on ec1 ec1_1 Index Cond: (((ff + 2) + 1) =3D ec1.f1) *************** explain (costs off) *** 229,248 **** union all select ff + 4 as x from ec1) as ss1 where ss1.x =3D ec1.f1 and ec1.ff =3D 42::int8 and ec1.ff =3D ec1.f1; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! --------------------------------------------------------------- Nested Loop Join Filter: ((((ec1_1.ff + 2) + 1)) =3D ec1.f1) -> Index Scan using ec1_pkey on ec1 ! Index Cond: ((ff =3D 42::bigint) AND (ff =3D 42::bigint)) Filter: (ff =3D f1) -> Append -> Index Scan using ec1_expr2 on ec1 ec1_1 ! Index Cond: (((ff + 2) + 1) =3D 42::bigint) -> Index Scan using ec1_expr3 on ec1 ec1_2 ! Index Cond: (((ff + 3) + 1) =3D 42::bigint) -> Index Scan using ec1_expr4 on ec1 ec1_3 ! Index Cond: ((ff + 4) =3D 42::bigint) (12 rows) =20=20 explain (costs off) --- 229,248 ---- union all select ff + 4 as x from ec1) as ss1 where ss1.x =3D ec1.f1 and ec1.ff =3D 42::int8 and ec1.ff =3D ec1.f1; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! ------------------------------------------------------------------- Nested Loop Join Filter: ((((ec1_1.ff + 2) + 1)) =3D ec1.f1) -> Index Scan using ec1_pkey on ec1 ! Index Cond: ((ff =3D '42'::bigint) AND (ff =3D '42'::bigint)) Filter: (ff =3D f1) -> Append -> Index Scan using ec1_expr2 on ec1 ec1_1 ! Index Cond: (((ff + 2) + 1) =3D '42'::bigint) -> Index Scan using ec1_expr3 on ec1 ec1_2 ! Index Cond: (((ff + 3) + 1) =3D '42'::bigint) -> Index Scan using ec1_expr4 on ec1 ec1_3 ! Index Cond: ((ff + 4) =3D '42'::bigint) (12 rows) =20=20 explain (costs off) *************** explain (costs off) *** 265,271 **** Nested Loop -> Nested Loop -> Index Scan using ec1_pkey on ec1 ! Index Cond: (ff =3D 42::bigint) -> Append -> Index Scan using ec1_expr2 on ec1 ec1_1 Index Cond: (((ff + 2) + 1) =3D ec1.f1) --- 265,271 ---- Nested Loop -> Nested Loop -> Index Scan using ec1_pkey on ec1 ! Index Cond: (ff =3D '42'::bigint) -> Append -> Index Scan using ec1_expr2 on ec1 ec1_1 Index Cond: (((ff + 2) + 1) =3D ec1.f1) *************** explain (costs off) *** 321,327 **** -> Sort Sort Key: ec1.f1 USING < -> Index Scan using ec1_pkey on ec1 ! Index Cond: (ff =3D 42::bigint) (20 rows) =20=20 -- check partially indexed scan --- 321,327 ---- -> Sort Sort Key: ec1.f1 USING < -> Index Scan using ec1_pkey on ec1 ! Index Cond: (ff =3D '42'::bigint) (20 rows) =20=20 -- check partially indexed scan *************** explain (costs off) *** 341,347 **** ----------------------------------------------------- Nested Loop -> Index Scan using ec1_pkey on ec1 ! Index Cond: (ff =3D 42::bigint) -> Append -> Index Scan using ec1_expr2 on ec1 ec1_1 Index Cond: (((ff + 2) + 1) =3D ec1.f1) --- 341,347 ---- ----------------------------------------------------- Nested Loop -> Index Scan using ec1_pkey on ec1 ! Index Cond: (ff =3D '42'::bigint) -> Append -> Index Scan using ec1_expr2 on ec1 ec1_1 Index Cond: (((ff + 2) + 1) =3D ec1.f1) *************** explain (costs off) *** 378,383 **** -> Sort Sort Key: ec1.f1 USING < -> Index Scan using ec1_pkey on ec1 ! Index Cond: (ff =3D 42::bigint) (14 rows) =20=20 --- 378,383 ---- -> Sort Sort Key: ec1.f1 USING < -> Index Scan using ec1_pkey on ec1 ! Index Cond: (ff =3D '42'::bigint) (14 rows) =20=20 diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected= /join.out index 57fc910..046b085 100644 *** a/src/test/regress/expected/join.out --- b/src/test/regress/expected/join.out *************** SELECT qq, unique1 *** 2544,2559 **** ( SELECT COALESCE(q2, -1) AS qq FROM int8_tbl b ) AS ss2 USING (qq) INNER JOIN tenk1 c ON qq =3D unique2; ! QUERY PLAN=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! -------------------------------------------------------------------------= ------------------------------ Nested Loop -> Hash Full Join ! Hash Cond: (COALESCE(a.q1, 0::bigint) =3D COALESCE(b.q2, (-1)::b= igint)) -> Seq Scan on int8_tbl a -> Hash -> Seq Scan on int8_tbl b -> Index Scan using tenk1_unique2 on tenk1 c ! Index Cond: (unique2 =3D COALESCE((COALESCE(a.q1, 0::bigint)), (= COALESCE(b.q2, (-1)::bigint)))) (8 rows) =20=20 SELECT qq, unique1 --- 2544,2559 ---- ( SELECT COALESCE(q2, -1) AS qq FROM int8_tbl b ) AS ss2 USING (qq) INNER JOIN tenk1 c ON qq =3D unique2; ! QUERY PLAN=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! -------------------------------------------------------------------------= -------------------------------- Nested Loop -> Hash Full Join ! Hash Cond: (COALESCE(a.q1, '0'::bigint) =3D COALESCE(b.q2, '-1':= :bigint)) -> Seq Scan on int8_tbl a -> Hash -> Seq Scan on int8_tbl b -> Index Scan using tenk1_unique2 on tenk1 c ! Index Cond: (unique2 =3D COALESCE((COALESCE(a.q1, '0'::bigint)),= (COALESCE(b.q2, '-1'::bigint)))) (8 rows) =20=20 SELECT qq, unique1 *************** select * from *** 3003,3012 **** ) ss where fault =3D 122 order by fault; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! ----------------------------------------------------------------- Nested Loop Left Join ! Filter: ((COALESCE(tenk1.unique1, (-1)) + int8_tbl.q1) =3D 122) -> Seq Scan on int8_tbl -> Index Scan using tenk1_unique2 on tenk1 Index Cond: (int8_tbl.q2 =3D unique2) --- 3003,3012 ---- ) ss where fault =3D 122 order by fault; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! -------------------------------------------------------------------------- Nested Loop Left Join ! Filter: ((COALESCE(tenk1.unique1, '-1'::integer) + int8_tbl.q1) =3D 12= 2) -> Seq Scan on int8_tbl -> Index Scan using tenk1_unique2 on tenk1 Index Cond: (int8_tbl.q2 =3D unique2) *************** explain (verbose, costs off) *** 4012,4025 **** select * from int8_tbl a left join lateral (select *, coalesce(a.q2, 42) as x from int8_tbl b) ss on a.q2 = =3D ss.q1; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! ---------------------------------------------------------------- Nested Loop Left Join ! Output: a.q1, a.q2, b.q1, b.q2, (COALESCE(a.q2, 42::bigint)) -> Seq Scan on public.int8_tbl a Output: a.q1, a.q2 -> Seq Scan on public.int8_tbl b ! Output: b.q1, b.q2, COALESCE(a.q2, 42::bigint) Filter: (a.q2 =3D b.q1) (7 rows) =20=20 --- 4012,4025 ---- select * from int8_tbl a left join lateral (select *, coalesce(a.q2, 42) as x from int8_tbl b) ss on a.q2 = =3D ss.q1; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! ------------------------------------------------------------------ Nested Loop Left Join ! Output: a.q1, a.q2, b.q1, b.q2, (COALESCE(a.q2, '42'::bigint)) -> Seq Scan on public.int8_tbl a Output: a.q1, a.q2 -> Seq Scan on public.int8_tbl b ! Output: b.q1, b.q2, COALESCE(a.q2, '42'::bigint) Filter: (a.q2 =3D b.q1) (7 rows) =20=20 *************** select * from *** 4235,4266 **** lateral (select q1, coalesce(ss1.x,q2) as y from int8_tbl d) ss2 ) on c.q2 =3D ss2.q1, lateral (select ss2.y offset 0) ss3; ! = QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! -------------------------------------------------------------------------= ---------------------------------------------------------------------------= -------------------------- Nested Loop ! Output: c.q1, c.q2, a.q1, a.q2, b.q1, (COALESCE(b.q2, 42::bigint)), d.= q1, (COALESCE((COALESCE(b.q2, 42::bigint)), d.q2)), ((COALESCE((COALESCE(b.= q2, 42::bigint)), d.q2))) -> Hash Right Join ! Output: c.q1, c.q2, a.q1, a.q2, b.q1, d.q1, (COALESCE(b.q2, 42::= bigint)), (COALESCE((COALESCE(b.q2, 42::bigint)), d.q2)) Hash Cond: (d.q1 =3D c.q2) -> Nested Loop ! Output: a.q1, a.q2, b.q1, d.q1, (COALESCE(b.q2, 42::bigint= )), (COALESCE((COALESCE(b.q2, 42::bigint)), d.q2)) -> Hash Left Join ! Output: a.q1, a.q2, b.q1, (COALESCE(b.q2, 42::bigint= )) Hash Cond: (a.q2 =3D b.q1) -> Seq Scan on public.int8_tbl a Output: a.q1, a.q2 -> Hash ! Output: b.q1, (COALESCE(b.q2, 42::bigint)) -> Seq Scan on public.int8_tbl b ! Output: b.q1, COALESCE(b.q2, 42::bigint) -> Seq Scan on public.int8_tbl d ! Output: d.q1, COALESCE((COALESCE(b.q2, 42::bigint)),= d.q2) -> Hash Output: c.q1, c.q2 -> Seq Scan on public.int8_tbl c Output: c.q1, c.q2 -> Result ! Output: (COALESCE((COALESCE(b.q2, 42::bigint)), d.q2)) (24 rows) =20=20 -- case that breaks the old ph_may_need optimization --- 4235,4266 ---- lateral (select q1, coalesce(ss1.x,q2) as y from int8_tbl d) ss2 ) on c.q2 =3D ss2.q1, lateral (select ss2.y offset 0) ss3; ! = QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! -------------------------------------------------------------------------= ---------------------------------------------------------------------------= -------------------------------- Nested Loop ! Output: c.q1, c.q2, a.q1, a.q2, b.q1, (COALESCE(b.q2, '42'::bigint)), = d.q1, (COALESCE((COALESCE(b.q2, '42'::bigint)), d.q2)), ((COALESCE((COALESC= E(b.q2, '42'::bigint)), d.q2))) -> Hash Right Join ! Output: c.q1, c.q2, a.q1, a.q2, b.q1, d.q1, (COALESCE(b.q2, '42'= ::bigint)), (COALESCE((COALESCE(b.q2, '42'::bigint)), d.q2)) Hash Cond: (d.q1 =3D c.q2) -> Nested Loop ! Output: a.q1, a.q2, b.q1, d.q1, (COALESCE(b.q2, '42'::bigi= nt)), (COALESCE((COALESCE(b.q2, '42'::bigint)), d.q2)) -> Hash Left Join ! Output: a.q1, a.q2, b.q1, (COALESCE(b.q2, '42'::bigi= nt)) Hash Cond: (a.q2 =3D b.q1) -> Seq Scan on public.int8_tbl a Output: a.q1, a.q2 -> Hash ! Output: b.q1, (COALESCE(b.q2, '42'::bigint)) -> Seq Scan on public.int8_tbl b ! Output: b.q1, COALESCE(b.q2, '42'::bigin= t) -> Seq Scan on public.int8_tbl d ! Output: d.q1, COALESCE((COALESCE(b.q2, '42'::bigint)= ), d.q2) -> Hash Output: c.q1, c.q2 -> Seq Scan on public.int8_tbl c Output: c.q1, c.q2 -> Result ! Output: (COALESCE((COALESCE(b.q2, '42'::bigint)), d.q2)) (24 rows) =20=20 -- case that breaks the old ph_may_need optimization diff --git a/src/test/regress/expected/rowtypes.out b/src/test/regress/expe= cted/rowtypes.out index 54525de..d3a98d1 100644 *** a/src/test/regress/expected/rowtypes.out --- b/src/test/regress/expected/rowtypes.out *************** ERROR: cannot compare dissimilar column *** 284,293 **** explain (costs off) select * from int8_tbl i8 where i8 in (row(123,456)::int8_tbl, '(4567890123456789,123)'); ! QUERY PLAN=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! -------------------------------------------------------------------------= ------------------------------------ Seq Scan on int8_tbl i8 ! Filter: (i8.* =3D ANY (ARRAY[ROW(123::bigint, 456::bigint)::int8_tbl, = '(4567890123456789,123)'::int8_tbl])) (2 rows) =20=20 select * from int8_tbl i8 --- 284,293 ---- explain (costs off) select * from int8_tbl i8 where i8 in (row(123,456)::int8_tbl, '(4567890123456789,123)'); ! QUERY PLAN=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! -------------------------------------------------------------------------= ---------------------------------------- Seq Scan on int8_tbl i8 ! Filter: (i8.* =3D ANY (ARRAY[ROW('123'::bigint, '456'::bigint)::int8_t= bl, '(4567890123456789,123)'::int8_tbl])) (2 rows) =20=20 select * from int8_tbl i8 diff --git a/src/test/regress/expected/union.out b/src/test/regress/expecte= d/union.out index a678e96..016571b 100644 *** a/src/test/regress/expected/union.out --- b/src/test/regress/expected/union.out *************** SELECT * FROM *** 654,666 **** UNION SELECT 2 AS t, 4 AS x) ss WHERE x > 3; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! -------------------------------------------------------------------------= --- Subquery Scan on ss Filter: (ss.x > 3) -> Unique -> Sort ! Sort Key: (1), (((random() * 3::double precision))::intege= r) -> Append -> Result -> Result --- 654,666 ---- UNION SELECT 2 AS t, 4 AS x) ss WHERE x > 3; ! QUERY PLAN=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ! -------------------------------------------------------------------------= ----- Subquery Scan on ss Filter: (ss.x > 3) -> Unique -> Sort ! Sort Key: (1), (((random() * '3'::double precision))::inte= ger) -> Append -> Result -> Result diff --git a/src/test/regress/expected/with.out b/src/test/regress/expected= /with.out index 6986f47..a31ec34 100644 *** a/src/test/regress/expected/with.out --- b/src/test/regress/expected/with.out *************** SELECT * FROM parent; *** 2083,2090 **** EXPLAIN (VERBOSE, COSTS OFF) WITH wcte AS ( INSERT INTO int8_tbl VALUES ( 42, 47 ) RETURNING q2 ) DELETE FROM a USING wcte WHERE aa =3D q2; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20 ! ------------------------------------------------ Delete on public.a Delete on public.a Delete on public.b --- 2083,2090 ---- EXPLAIN (VERBOSE, COSTS OFF) WITH wcte AS ( INSERT INTO int8_tbl VALUES ( 42, 47 ) RETURNING q2 ) DELETE FROM a USING wcte WHERE aa =3D q2; ! QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20 ! ---------------------------------------------------- Delete on public.a Delete on public.a Delete on public.b *************** DELETE FROM a USING wcte WHERE aa =3D q2; *** 2094,2100 **** -> Insert on public.int8_tbl Output: int8_tbl.q2 -> Result ! Output: 42::bigint, 47::bigint -> Nested Loop Output: a.ctid, wcte.* Join Filter: (a.aa =3D wcte.q2) --- 2094,2100 ---- -> Insert on public.int8_tbl Output: int8_tbl.q2 -> Result ! Output: '42'::bigint, '47'::bigint -> Nested Loop Output: a.ctid, wcte.* Join Filter: (a.aa =3D wcte.q2) ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs ------- =_aaaaaaaaaa0--