[no subject]
---------------------------------
All new Yahoo! Mail -
---------------------------------
Get a sneak peak at messages with a handy reading pane.
--0-878230187-1152221686=:95484
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
<div>I have a problem with a query that in postgres 7.4 and 8.12 has an acceptable response time but in postgres 8.14 is very slow.<BR> <BR>This is the table I use:<BR> <BR> create table TEST (<BR> TESTID INT8 not null,<BR> TESTTYPE INT4 null,<BR> constraint PK_TESTID primary key (TESTID));<BR> create index IX_TEST_TESTTYPE on TEST (TESTTYPE);<BR> <BR>And this is the query with the problem:</div> <div> explain select max(TESTID) from TEST where TESTTYPE = 1577;<BR> <BR>The query plan in postgres 7.4 and 8.12 is using the index by TESTTYPE field, which is what I want in this
case.<BR> QUERY PLAN <BR> Aggregate (cost=25.97..25.97 rows=1 width=8) <BR> -> Index Scan using ix_test_testtype on test (cost=0.00..25.95 rows=9 width=8) <BR> Index Cond: (testtype = 1577) </div> <div>With postgres 8.14 the query plan uses the primary key PK_TESTID with filter by TESTTYPE, which it takes almost 10 minutes to execute:<BR> QUERY PLAN <BR> Limit (cost=0.00..41.46 rows=1 width=8) <BR> -> Index Scan Backward using pk_testid on test (cost=?)
<BR> Filter: ((testid IS NOT NULL) and (testtype = 1577))<BR> <BR>When replacing the index <BR> create index IX_TEST_TESTTYPE on TEST (TESTTYPE);<BR>with <BR> create index IX_TEST_TESTTYPE on TEST (TESTTYPE, TESTID);<BR>the query plan uses this index and the execution of this select is extremely fast. <BR> <BR>From what I can see, the query plan for 8.14 is using a index scan by the field used with max() function with a filter by the field in the where condition.<BR>Should not the query plan use an index scan by the field in where condition (which in my case is a small range) and come up with the max value in that range?<BR> <BR>Is this a bug, am I missing a configuration step or this is how it is supposed
to work? <BR> <BR>Thank you very much,<BR>Ioana <BR></div><p> 
<hr size=1> <a href="http://us.rd.yahoo.com/evt=40705/*http://mrd.mail.yahoo.com/try_beta?.intl=ca"><b>All new Yahoo! Mail - </b></a>
<hr size=1>Get a sneak peak at messages with a handy reading pane.
--0-878230187-1152221686=:95484--
Home |
Main Index |
Thread Index