Help on query plan. (was: select like and indexes)

From: "William N(dot) Zanatta" <william(at)veritel(dot)com(dot)br>
To: pgsql-general(at)postgresql(dot)org
Subject: Help on query plan. (was: select like and indexes)
Date: 2003-01-20 19:59:14
Message-ID: 3E2C5512.1000601@veritel.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Well guys,

I made a search on the archives and found a message on my issue.
It's subject is: "Why won't the query planner use my index?".

There was a suggestion of setting 'enable_seqscan' to off to see
whether the query planner was chosing the right way or not.

Here goes my results:

access=# explain analyze select * from tbl_access where ip like '12%157';
QUERY PLAN
-------------------------------------------------------------------
Seq Scan on tbl_access (cost=0.00..42519.84 rows=139 width=134)
(actual time=698.03..20504.07 rows=1391 loops=1)
Filter: (ip ~~ '12%157'::text)
Total runtime: 20507.44 msec
(3 rows)

-------------------------------------------------------------------

access=# SET enable_seqscan = off;
SET
access=# explain analyze select * from tbl_access where ip like '12%157';
QUERY PLAN

-------------------------------------------------------------------
Index Scan using teste1 on tbl_access (cost=0.00..63593.03 rows=139
width=134) (actual time=160.69..1177.26 rows=1391 loops=1)
Index Cond: ((ip >= '12'::character varying) AND (ip <
'13'::character varying))
Filter: (ip ~~ '12%157'::text)
Total runtime: 1181.18 msec
(4 rows)

--------------------------------------------------------------------

Well, although PG is chosing for a Sequential Scan, the Index Scan
showed to be much more faster.

Is that a problem with the planner or a normal behavior?

william

--
Perl combines all of the worst aspects of BASIC, C and line noise.
-- Keith Packard

Responses

Browse pgsql-general by date

  From Date Subject
Next Message elein 2003-01-20 20:18:25 Re: Writing apps for ORDBMS
Previous Message Stephan Szabo 2003-01-20 19:56:19 Re: select like and indexes