Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am admittedly speaking up somewhat late here, and may be completely off base, but it seems to me that the "LIKE" operation is almost always going to be a loser, performance-wise, when there is an initial wildcard, e.g. "%superman re%" will require a sequential scan, while "superman re%" would not (assuming proper indexes matching case and type).

I'd suggest tsearch2, possibly, which uses GIST indexes and may perhaps be a better match for this sort of problem.

HTH,

Greg Williamson
DBA
GlobeXplorer LLC

-----Original Message-----
From:	pgsql-general-owner@xxxxxxxxxxxxxx on behalf of Richard Huxton
Sent:	Thu 11/9/2006 1:22 AM
To:	Thomas H.
Cc:	pgsql-general@xxxxxxxxxxxxxx
Subject:	Re: [GENERAL] planer picks a bad plan (seq-scan instead of index)

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%')
> --------------------

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_soundmedia ON sm_info_ean = dvd_ean

I'd also be tempted to look at a tsearch2 setup for the word searches.
-- 
   Richard Huxton
   Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match


-------------------------------------------------------
Click link below if it is SPAM gsw@xxxxxxxxxxxxxxxx
"https://mailscanner.globexplorer.com/dspam/dspam.cgi?signatureID=4552efed289104295495211&user=gsw@xxxxxxxxxxxxxxxx&retrain=spam&template=history&history_page=1";
!DSPAM:4552efed289104295495211!
-------------------------------------------------------







[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux