From: Anthony Presley <anthony@resolution.com>
To: Pgsql-Performance ((((E-mail)))) <pgsql-performance@postgresql.org>
Subject: Why is it choosing a different plan?
Date: Fri, 22 Sep 2006 17:59:16 -0500
Message-ID: <1158965956.8070.12.camel@puma> (raw)
Hi all, I'm having some confusion with the 7.4 query planner.
I have two identical queries, whereby the passed (varchar) parameter
appears to be the deciding factor between a sequential or an index scan.
IE, This query:
explain SELECT DISTINCT (a1.ENTRY_ID) AS retrieved FROM OS_CURRENTSTEP
AS a1 , OS_CURRENTSTEP AS a2 WHERE a1.ENTRY_ID = a1.ENTRY_ID AND
a1.ENTRY_ID = a2.ENTRY_ID AND ( a1.OWNER = 'p1' AND a2.STEP_ID =
1 );
NOTICE: QUERY PLAN:
Unique (cost=1175.88..1175.88 rows=1 width=16)
-> Sort (cost=1175.88..1175.88 rows=1 width=16)
-> Nested Loop (cost=0.00..1175.87 rows=1 width=16)
-> Index Scan using idx_9 on os_currentstep a1
(cost=0.00..1172.45 rows=1 width=8)
-> Index Scan using idx_8 on os_currentstep a2
(cost=0.00..3.41 rows=1 width=8)
However, this query:
explain SELECT DISTINCT (a1.ENTRY_ID) AS retrieved FROM OS_CURRENTSTEP
AS a1 , OS_CURRENTSTEP AS a2 WHERE a1.ENTRY_ID = a1.ENTRY_ID AND
a1.ENTRY_ID = a2.ENTRY_ID AND ( a1.OWNER = 'GIL' AND a2.STEP_ID =
1 );
NOTICE: QUERY PLAN:
Unique (cost=3110.22..3110.22 rows=1 width=16)
-> Sort (cost=3110.22..3110.22 rows=1 width=16)
-> Nested Loop (cost=0.00..3110.21 rows=1 width=16)
-> Seq Scan on os_currentstep a1 (cost=0.00..3106.78
rows=1 width=8)
-> Index Scan using idx_8 on os_currentstep a2
(cost=0.00..3.41 rows=1 width=8)
Thoughts about why changing OWNER from 'p1' to 'GIL' would go from an
Index Scan to a Sequential?
[There is an index on os_currentstep, and it was vacuum analyze'd
recently.]
Running version 7.4 (working on upgrading to 8.0 soon). Thanks!
--
Anthony
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: anthony@resolution.com
Subject: Re: Why is it choosing a different plan?
In-Reply-To: <1158965956.8070.12.camel@puma>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox