Efficiency again...

From: Michael Richards <miker(at)scifair(dot)acadiau(dot)ca>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Efficiency again...
Date: 1998-07-22 23:17:33
Message-ID: Pine.BSF.3.96.980722200758.16508A-100000@scifair.acadiau.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi.
I just noticed something interesting. I don't know if my idea is better or
if it wasn't implemented because it violates some SQL rule...

searchengine=> create table test ( test1 int4, test2 int4);
CREATE
searchengine=> create index test_itest1 on test (test1);
CREATE
<insert a pile of data so it looks like so>
searchengine=> select * from test;
test1|test2
-----+-----
1| 3
1| 5
1| 9
2| 1
2| 3
2| 6
2| 9
3| 9
4| 5
(9 rows)

Now here is the plan I expect for a single test1 value
searchengine=> explain select * from test where test1=1;
Index Scan on test (cost=0.00 size=0 width=8)

But look:
searchengine=> explain select * from test where test1=1 or test1=2;
Seq Scan on test (cost=0.00 size=0 width=8)

ugh! Sequential. This may be OK for a small database, but in my
application I have many rows:
searchengine=> explain select * from word_detail where word_id=23423 or
word_id=68548;

Seq Scan on word_detail (cost=205938.73 size=510342 width=10)

That costs a _LOT_.

Wouldn't it be better to do n sequential scans where n is the number of
or'd together values? Using IN doesn't help out either...

searchengine=> explain select * from test where test1 IN (5,9);
Seq Scan on test (cost=0.00 size=0 width=8)

Sometimes I wish I had the power to tell the DBMS how I wanted a query
done...

-Mike

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1998-07-23 00:40:58 Re: [HACKERS] Efficiency again...
Previous Message Ken McGlothlen 1998-07-22 22:34:16 Re: [GENERAL] Re: [HACKERS] [Fwd: SGVLLUG Oracle and Informix on Linux]