Re: [GENERAL] planer picks a bad plan (seq-scan instead of index) when adding an additional join

2006-11-09 Thread Thomas H.
I wrote: This didn't matter a whole lot back when the planner couldn't reorder outer joins, but now that it can, it's more important that the estimates be accurate. I'm not sure if this is feasible to fix before 8.2, but I'll take a look. Actually, the changes were far more localized than I

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index) when adding an additional join

2006-11-09 Thread Tom Lane
I wrote: > This didn't matter a whole lot back when the planner couldn't reorder > outer joins, but now that it can, it's more important that the estimates > be accurate. > I'm not sure if this is feasible to fix before 8.2, but I'll take a > look. Actually, the changes were far more localized th

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index) when adding an additional join

2006-11-09 Thread Tom Lane
"Thomas H." <[EMAIL PROTECTED]> writes: >> Um, what's the datatype of sm_info_ean and dvd_ean exactly? > varchar(15) and varchar(14) OK. I was wondering if you'd tried to use the new contrib/isn code and it was messing up the estimates somehow. Seems like a red herring. After looking more clos

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index) when adding an additional join

2006-11-09 Thread Thomas H.
SELECT * FROM shop.dvds LEFT JOIN oldtables.movies ON mov_id = dvd_mov_id LEFT JOIN shop.data_soundmedia ON sm_info_ean = dvd_ean WHERE (lower(mov_name) LIKE '%superman re%' OR lower(dvd_name) like '%superman re%' OR lower(dvd_edition) LIKE '%superman re%') Um, what's the datatype of sm_info_ean

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index) when adding an additional join

2006-11-09 Thread Tom Lane
"Thomas H." <[EMAIL PROTECTED]> writes: > SELECT * FROM shop.dvds > LEFT JOIN oldtables.movies ON mov_id = dvd_mov_id > LEFT JOIN shop.data_soundmedia ON sm_info_ean = dvd_ean > WHERE (lower(mov_name) LIKE '%superman re%' OR lower(dvd_name) like > '%superman re%' OR lower(dvd_edition) LIKE '%super

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index)

2006-11-09 Thread Richard Huxton
Thomas H. wrote: OK - in that case try explicit subqueries: SELECT ... FROM (SELECT * FROM shop.dvds LEFT JOIN shop.oldtables.movies WHERE lower(mov_name) LIKE ... ) AS bar LEFT JOIN shop.data_soundmedia same result, have tried this as well (22sec). it's the LEFT JOIN shop.data_soundmedia

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index)

2006-11-09 Thread Thomas H.
OK - in that case try explicit subqueries: SELECT ... FROM (SELECT * FROM shop.dvds LEFT JOIN shop.oldtables.movies WHERE lower(mov_name) LIKE ... ) AS bar LEFT JOIN shop.data_soundmedia same result, have tried this as well (22sec). it's the LEFT JOIN shop.data_soundmedia for which the plan

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index)

2006-11-09 Thread Richard Huxton
Thomas H. wrote: Try putting your conditions as part of the join: SELECT * FROM shop.dvds LEFT JOIN oldtables.movies ON mov_id = dvd_mov_id AND ( lower(mov_name) LIKE '%superman re%' OR lower(dvd_name) like '%superman re%' OR lower(dvd_edition) LIKE '%superman re%' ) LEFT JOIN

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index)

2006-11-09 Thread Thomas H.
Try putting your conditions as part of the join: SELECT * FROM shop.dvds LEFT JOIN oldtables.movies ON mov_id = dvd_mov_id AND ( lower(mov_name) LIKE '%superman re%' OR lower(dvd_name) like '%superman re%' OR lower(dvd_edition) LIKE '%superman re%' ) LEFT JOIN shop.data_soundme

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index) when adding an additional join

2006-11-09 Thread Thomas H.
1. You MUST sequence scan dvds, as there is no way to do an index search on a like with % at the beginning. 2. You are asking for a left join on dvds, which means you want all records, so you must sequence scan dvds. The filters are all OR, so you can't say that a records is excluded until AFTE

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index)

2006-11-09 Thread Russell Smith
Thomas H. wrote: hi list. as soon as i left-join an additional table, the query takes 24sec instead of 0.2sec, although the added fields have no impact on the resultset: SELECT * FROM shop.dvds LEFT JOIN oldtables.movies ON mov_id = dvd_mov_id WHERE (lower(mov_name) LIKE

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index)

2006-11-09 Thread Gregory S. Williamson
TECTED] on behalf of Richard Huxton Sent: Thu 11/9/2006 1:22 AM To: Thomas H. Cc: pgsql-general@postgresql.org Subject: Re: [GENERAL] planer picks a bad plan (seq-scan instead of index) Thomas H. wrote: > > SELECT * FROM shop.dvds > LEFT JOIN oldtabl

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index)

2006-11-09 Thread Richard Huxton
Thomas H. wrote: SELECT * FROM shop.dvds LEFT JOIN oldtables.movies ON mov_id = dvd_mov_id LEFT JOIN shop.data_soundmedia ON sm_info_ean = dvd_ean WHERE (lower(mov_name) LIKE '%superman re%' OR lower(dvd_name) like '%superman re%' OR lower(dvd_edition) LIKE '%superman re%')

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index)

2006-11-09 Thread Alban Hertroys
Thomas H. wrote: hi list. as soon as i left-join an additional table, the query takes 24sec instead of 0.2sec, although the added fields have no impact on the resultset: SELECT * FROM shop.dvds LEFT JOIN oldtables.movies ON mov_id = dvd_mov_id WHERE (lower(mov_name) LIKE

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index)

2006-11-08 Thread Thomas H.
Have you run analyze on all the three tables since creating the database? yes. even a forced ANALYZE FULL after the table loads: the tables were TRUNCATE'd, refilled and ANALYZE FULL'ed some minutes before the tests. there where no UPDATEs after the INSERTs... - thomas -

Re: [GENERAL] planer picks a bad plan (seq-scan instead of index)

2006-11-08 Thread mike
Have you run analyze on all the three tables since creating the database? What On Thu, 2006-11-09 at 02:31 +0100, Thomas H. wrote: > hi list. > > as soon as i left-join an additional table, the query takes 24sec instead of > 0.2sec, although the added fields have no impact on the resultset: >

[GENERAL] planer picks a bad plan (seq-scan instead of index) when adding an additional join

2006-11-08 Thread Thomas H.
hi list. as soon as i left-join an additional table, the query takes 24sec instead of 0.2sec, although the added fields have no impact on the resultset: SELECT * FROM shop.dvds LEFT JOIN oldtables.movies ON mov_id = dvd_mov_id WHERE (lower(mov_name) LIKE '%superman re%' OR