Query planner issue - Mailing list pgsql-general

From Andrea Moretto
Subject Query planner issue
Date
Msg-id 1AA72A96-DA40-4A7B-8142-448D6E36373C@gmail.com
Whole thread Raw
Responses Re: Query planner issue
Re: Query planner issue
Re: Query planner issue
List pgsql-general
Hi there,

   I am currently running Postgres 8.3.1.

I've got a table called DETAILS, the primary key is : DE_ID char(12),
there is another field CO_ID char (12).
DE_ID and CO_ID are indexed with a btree. This table is about 140
millions of records.

If I execute an "explain select * from details where co_id =
'010076015372';" it uses the index. Here follows the plan:

"Index Scan using idx_co_id on details  (cost=0.00..34.37 rows=2
width=741)"
"  Index Cond: ((co_id)::bpchar = '010076015372'::bpchar)"


If I run "explain analyze select * from details where co_id || co_id =
'0100760153722324445';" it runs a sequential scan not using the index
(which takes about 1000000 times than using the index):

  Seq Scan on details  (cost=0.00..8755139.52 rows=819131 width=741)
    Filter: (((co_id)::text || (co_id)::text) =
'010076015372010076015372'::text)

Same thing if I try to trick it using a view or a stored procedure.
Query planner is not easy to trick!

My question is : is there a way to use the index or isn't it possible?

Thanks in advance.

Andrea Moretto

Andrea Moretto
moretto.andrea@gmail.com
-------------------------------------------------------
CONFIDENTIALITY NOTICE
This message and its attachments are addressed solely to the persons
above and may contain confidential information. If you have received
the message in error, be informed that any use of the content hereof
is prohibited. Please return it immediately to the sender and delete
the message.
-------------------------------------------------------


pgsql-general by date:

Previous
From: "Pavel Stehule"
Date:
Subject: Re: Synchronize two similar tables: recursive triggers
Next
From: Richard Huxton
Date:
Subject: Re: Query planner issue