BUG #5542: Query optimization problem - Mailing list pgsql-bugs

From Roman
Subject BUG #5542: Query optimization problem
Date
Msg-id 201007060643.o666hlPa017398@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #5542: Query optimization problem
Re: BUG #5542: Query optimization problem
List pgsql-bugs
The following bug has been logged online:

Bug reference:      5542
Logged by:          Roman
Email address:      zotov@oe-it.ru
PostgreSQL version: 9.0
Operating system:   Win7 x64
Description:        Query optimization problem
Details:

I have a query:

SELECT d1.ID, d2.ID
FROM DocPrimary d1
  JOIN DocPrimary d2 ON d2.BasedOn=d1.ID
WHERE (d1.ID=234409763) or (d2.ID=234409763)

i think what QO(Query Optimizer) can make it faster (now it seq scan and on
million records works 7 sec)

SELECT d1.ID, d2.ID
FROM DocPrimary d1
  JOIN DocPrimary d2 ON d2.BasedOn=d1.ID
WHERE (d2.BasedOn=234409763) or (d2.ID=234409763)

Result of this query are identical (and can get by replace part of where use
join dependence)
And it works 0-10ms

I think, what QO can undertstand it self.

Table create query:

CREATE TABLE docprimary
(
  id integer NOT NULL,
  basedon integer,
  CONSTRAINT id_pk PRIMARY KEY (id)
);

CREATE INDEX basedon_idx
  ON docprimary
  USING btree
  (basedon);

pgsql-bugs by date:

Previous
From: Dimitri Fontaine
Date:
Subject: Re: BUG #5532: Valid UTF8 sequence errors as invalid
Next
From: Merlin Moncure
Date:
Subject: ERROR: cannot handle unplanned sub-select