From: | Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | vadim(at)krs(dot)ru (Vadim Mikheev) |
Cc: | bamby(at)marka(dot)net(dot)ua, hackers(at)postgreSQL(dot)org |
Subject: | Re: [HACKERS] Re: [BUGS] General Bug Report: Bug in optimizer |
Date: | 1999-03-18 21:33:11 |
Message-ID: | 199903182133.QAA08693@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs pgsql-hackers |
> Bruce Momjian wrote:
> >
> > Let me tell you why I don't think this is a bug. The optimizer will
> > choose ordered results over unordered results if the costs are the same.
> > In this case, the cost of the query is zero, so it chose to use the
> > index because the index produces an ordered result.
> >
> > This works well for un-vacuumed tables, because it thinks everything is
> > zero cost, and chooses the index.
>
> Agreed, this is ok as long as
>
> vac=> create table table1 (field1 int);
> CREATE
> vac=> insert into table1 values (1);
> INSERT 1583349 1
> vac=> create index i_table1__field1 on table1 (field1);
> CREATE
> vac=> explain select * from table1 where field1 = 1;
> NOTICE: QUERY PLAN:
>
> Seq Scan on table1 (cost=1.03 size=1 width=4)
>
> - SeqScan is used for small tables.
>
> So, only bug reported is left.
>
> Vadim
>
Fixed:
test=> explain select * from table1 where field1 = 1;
NOTICE: QUERY PLAN:
Index Scan using i_table1__field1 on table1 (cost=0.00 size=0 width=4)
EXPLAIN
test=> explain select * from table1 where field1 = -1;
NOTICE: QUERY PLAN:
Index Scan using i_table1__field1 on table1 (cost=0.00 size=0 width=4)
The function fixing it is in gram.y:
static Node *doNegate(Node *n)
{
if (IsA(n, A_Const))
{
A_Const *con = (A_Const *)n;
if (con->val.type == T_Integer)
{
con->val.val.ival = -con->val.val.ival;
return n;
}
if (con->val.type == T_Float)
{
con->val.val.dval = -con->val.val.dval;
return n;
}
}
return makeA_Expr(OP, "-", NULL, n);
}
It tries to merge the negative into the constant. We already had
special '-' handling in the grammer, so I just call this function,
rather than doing makeA_Expr in all cases.
Committed.
--
Bruce Momjian | http://www.op.net/~candle
maillist(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
From | Date | Subject | |
---|---|---|---|
Next Message | The Hermit Hacker | 1999-03-19 13:32:16 | Re: [HACKERS] Re: [BUGS] General Bug Report: Bug in optimizer |
Previous Message | Bruce Momjian | 1999-03-18 20:13:23 | Re: [HACKERS] Re: [BUGS] General Bug Report: Bug in optimizer |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 1999-03-19 02:40:03 | Removing derived files from CVS |
Previous Message | Bruce Momjian | 1999-03-18 20:13:23 | Re: [HACKERS] Re: [BUGS] General Bug Report: Bug in optimizer |