Re: [GENERAL] Postgres optimizer choosing wrong index

2008-10-28 Thread Jack Orenstein
Tom Lane wrote: Jack Orenstein <[EMAIL PROTECTED]> writes: EXPLAIN says that the correct index is being used -- it didn't used to. However, pg_stat* says otherwise. In my test, I have exactly one dh value. Running EXPLAIN with this value produces a plan using idx_dh (the correct index), but pg_s

Re: [GENERAL] Postgres optimizer choosing wrong index

2008-10-27 Thread Tom Lane
Jack Orenstein <[EMAIL PROTECTED]> writes: > EXPLAIN says that the correct index is being used -- it didn't used > to. However, pg_stat* says otherwise. In my test, I have exactly one > dh value. Running EXPLAIN with this value produces a plan using idx_dh > (the correct index), but pg_stats says t

Re: [GENERAL] Postgres optimizer choosing wrong index

2008-10-27 Thread Jack Orenstein
Tom Lane wrote: Jack Orenstein <[EMAIL PROTECTED]> writes: - I created two schemas, NOVAC and VAC, each with a table T as described above. - Before loading data, I ran VACUUM ANALYZE on VAC.T. - I then started loading data. The workload is a mixture of INSERT, SELECT and UPDATE. For SELE

Re: [GENERAL] Postgres optimizer choosing wrong index

2008-10-24 Thread Tom Lane
Jack Orenstein <[EMAIL PROTECTED]> writes: > - I created two schemas, NOVAC and VAC, each with a table T as described > above. > - Before loading data, I ran VACUUM ANALYZE on VAC.T. > - I then started loading data. The workload is a mixture of INSERT, SELECT > and > UPDATE. For SELECT and U

Re: [GENERAL] Postgres optimizer choosing wrong index

2008-10-24 Thread Jack Orenstein
Tom Lane wrote: Jack Orenstein <[EMAIL PROTECTED]> writes: I may have simplified too far. Our application runs a number of different queries. All our WHERE clauses restrict dh and fh. For a given pair of (dh, fh) values, the initial query should come up empty and then insert this pair, and then

Re: [GENERAL] Postgres optimizer choosing wrong index

2008-10-23 Thread Tom Lane
Jack Orenstein <[EMAIL PROTECTED]> writes: > I may have simplified too far. Our application runs a number of > different queries. All our WHERE clauses restrict dh and fh. For a > given pair of (dh, fh) values, the initial query should come up empty > and then insert this pair, and then there is fu

Re: [GENERAL] Postgres optimizer choosing wrong index

2008-10-23 Thread Jack Orenstein
Tom Lane wrote: Jack Orenstein <[EMAIL PROTECTED]> writes: Tom Lane wrote: If you plug in a value that *does* occur in the table it should probably choose the more-relevant index consistently. Unfortunately, it matters a lot at runtime. The dh value is not very selective, as shown by the sta

Re: [GENERAL] Postgres optimizer choosing wrong index

2008-10-23 Thread Jack Orenstein
Researching this some more, it appears to be the case that VACUUM (by itself, no ANALYZE) is changing the optimizer's behavior. Here is a self-contained test: select '*** drop t'; drop table t cascade; select '*** create t(dh, fh, nm, filler)'; create table t (dh int, fh int, nm int, filler ch

Re: [GENERAL] Postgres optimizer choosing wrong index

2008-10-23 Thread Tom Lane
Jack Orenstein <[EMAIL PROTECTED]> writes: > Tom Lane wrote: >> If you plug in a value that *does* occur in the table it should probably >> choose the more-relevant index consistently. > Unfortunately, it matters a lot at runtime. The dh value is not very > selective, > as shown by the statistic

Re: [GENERAL] Postgres optimizer choosing wrong index

2008-10-23 Thread Jack Orenstein
Tom Lane wrote: Jack Orenstein <[EMAIL PROTECTED]> writes: If I run EXPLAIN on this query, (plugging in values 1 and 2 for the variables), before VACUUM ANALYZE, I get the desired execution plan: Index Scan using idx_df on T (cost=0.00..4.83 rows=1 width=454) Index Cond: ((dh = 1) AND

Re: [GENERAL] Postgres optimizer choosing wrong index

2008-10-23 Thread Tom Lane
Jack Orenstein <[EMAIL PROTECTED]> writes: > If I run EXPLAIN on this query, (plugging in values 1 and 2 for the > variables), > before VACUUM ANALYZE, I get the desired execution plan: > Index Scan using idx_df on T (cost=0.00..4.83 rows=1 width=454) > Index Cond: ((dh = 1) AND (fh = 2))

[GENERAL] Postgres optimizer choosing wrong index

2008-10-23 Thread Jack Orenstein
I'm using postgres 7.4 and having a problem with the query optimizer. Our table, T, looks like this: dh int fh int nm int ... -- other columns A typical row is 400-500 bytes. T has two indexes, idx_df on (dh, fh) and idx_dn on (dh, nm). My query is