dbTalk Databases Forums  

Re: [BUGS] 7.4 aggregate OR TRUE yields strange results

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss Re: [BUGS] 7.4 aggregate OR TRUE yields strange results in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] 7.4 aggregate OR TRUE yields strange results - 02-13-2004 , 04:06 PM






"=?iso-8859-2?B?U1rbQ1MgR+Fib3I=?=" <surrano (AT) mailbox (DOT) hu> writes:
Quote:
SELECT count(*)<0 OR TRUE FROM mytable WHERE condition
dumps the whole tuples meeting the condition.
Wow, that's bizarre. The "x OR TRUE" expression will get simplified to
just TRUE, so that COUNT isn't really there at all, but that shouldn't
change the query semantics. And it seems to work correctly in 7.3.*
and before. Looking into it ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] 7.4 aggregate OR TRUE yields strange results - 02-13-2004 , 04:39 PM






"=?iso-8859-2?B?U1rbQ1MgR+Fib3I=?=" <surrano (AT) mailbox (DOT) hu> writes:
Quote:
SELECT count(*)<0 OR TRUE FROM mytable WHERE condition
dumps the whole tuples meeting the condition.
Sigh, I'm an idiot. I introduced this bug more than a year ago.
(Bit surprising that it wasn't caught already...) Patch against 7.4.*
is attached.

regards, tom lane

Index: planner.c
================================================== =================
RCS file: /cvsroot/pgsql-server/src/backend/optimizer/plan/planner.c,v
retrieving revision 1.161
diff -c -r1.161 planner.c
*** planner.c 25 Sep 2003 06:58:00 -0000 1.161
--- planner.c 13 Feb 2004 22:22:26 -0000
***************
*** 701,719 ****

/*
* Will need actual number of aggregates for estimating costs.
- * Also, it's possible that optimization has eliminated all
- * aggregates, and we may as well check for that here.
*
* Note: we do not attempt to detect duplicate aggregates here; a
* somewhat-overestimated count is okay for our present purposes.
*/
if (parse->hasAggs)
- {
numAggs = count_agg_clause((Node *) tlist) +
count_agg_clause(parse->havingQual);
- if (numAggs == 0)
- parse->hasAggs = false;
- }

/*
* Figure out whether we need a sorted result from query_planner.
--- 701,718 ----

/*
* Will need actual number of aggregates for estimating costs.
*
* Note: we do not attempt to detect duplicate aggregates here; a
* somewhat-overestimated count is okay for our present purposes.
+ *
+ * Note: think not that we can turn off hasAggs if we find no aggs.
+ * It is possible for constant-expression simplification to remove
+ * all explicit references to aggs, but we still have to follow the
+ * aggregate semantics (eg, producing only one output row).
*/
if (parse->hasAggs)
numAggs = count_agg_clause((Node *) tlist) +
count_agg_clause(parse->havingQual);

/*
* Figure out whether we need a sorted result from query_planner.

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.