Except all eliminates what it shouldnt

Started by PostgreSQL Bugs Listover 24 years ago2 messagesbugs
Jump to latest
#1PostgreSQL Bugs List
pgsql-bugs@postgresql.org

Gerzson Szinyei (gerzson@elender.hu) reports a bug with a severity of 1
The lower the number the more severe it is.

Short Description
Except all eliminates what it shouldnt

Long Description
"except all" eliminates records which had 2 instances in the original table, and one instance in the table to be eliminated. One instance should have showed up in the result.
When I filter the original table with "where field=nnnn", (the id of the problem record), and do the "except all" for only the records in questtion, the result is one instance as it should be.

Sample Code
http://www.webit.hu/~gerzson/pgexceptbugtest.tgz

No file was uploaded with this report

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: PostgreSQL Bugs List (#1)
Re: Except all eliminates what it shouldnt

pgsql-bugs@postgresql.org writes:

Except all eliminates what it shouldnt

Hmm, nasty. It looks like all nested cases of INTERSECT/EXCEPT are
broken.

Attached is a patch I've applied to CVS sources (7.2-to-be). I don't
have enough confidence in it to back-patch it into 7.1.* right now,
but if you want to apply it locally I think it will work for you.

regards, tom lane

*** src/backend/optimizer/prep/prepunion.c.orig	Tue Jun  5 01:26:04 2001
--- src/backend/optimizer/prep/prepunion.c	Tue Aug 14 12:55:33 2001
***************
*** 275,286 ****
  	 *
  	 * The tlist for an Append plan isn't important as far as the Append is
  	 * concerned, but we must make it look real anyway for the benefit of
! 	 * the next plan level up.
  	 */
  	plan = (Plan *)
  		make_append(makeList2(lplan, rplan),
  					false,
! 					generate_setop_tlist(op->colTypes, 0, false,
  										 lplan->targetlist,
  										 refnames_tlist));
--- 275,288 ----
  	 *
  	 * The tlist for an Append plan isn't important as far as the Append is
  	 * concerned, but we must make it look real anyway for the benefit of
! 	 * the next plan level up.  In fact, it has to be real enough that the
! 	 * flag column is shown as a variable not a constant, else setrefs.c
! 	 * will get confused.
  	 */
  	plan = (Plan *)
  		make_append(makeList2(lplan, rplan),
  					false,
! 					generate_setop_tlist(op->colTypes, 2, false,
  										 lplan->targetlist,
  										 refnames_tlist));
***************
*** 353,358 ****
--- 355,367 ----
  /*
   * Generate targetlist for a set-operation plan node
+  *
+  * colTypes: column datatypes for non-junk columns
+  * flag: -1 if no flag column needed, 0 or 1 to create a const flag column,
+  *       2 to create a variable flag column
+  * hack_constants: true to copy up constants (see comments in code)
+  * input_tlist: targetlist of this node's input node
+  * refnames_tlist: targetlist to take column names from
   */
  static List *
  generate_setop_tlist(List *colTypes, int flag,
***************
*** 414,432 ****

if (flag >= 0)
{
! /* Add a resjunk column yielding specified flag value */
resdom = makeResdom((AttrNumber) resno++,
INT4OID,
-1,
pstrdup("flag"),
true);
! expr = (Node *) makeConst(INT4OID,
! sizeof(int4),
! Int32GetDatum(flag),
! false,
! true,
! false,
! false);
tlist = lappend(tlist, makeTargetEntry(resdom, expr));
}

--- 423,454 ----

if (flag >= 0)
{
! /* Add a resjunk flag column */
resdom = makeResdom((AttrNumber) resno++,
INT4OID,
-1,
pstrdup("flag"),
true);
! if (flag <= 1)
! {
! /* flag value is the given constant */
! expr = (Node *) makeConst(INT4OID,
! sizeof(int4),
! Int32GetDatum(flag),
! false,
! true,
! false,
! false);
! }
! else
! {
! /* flag value is being copied up from subplan */
! expr = (Node *) makeVar(0,
! resdom->resno,
! INT4OID,
! -1,
! 0);
! }
tlist = lappend(tlist, makeTargetEntry(resdom, expr));
}