Received: from maia.hub.org (unknown [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 2F4841337C2C for ; Mon, 9 May 2011 15:45:23 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 62898-10 for ; Mon, 9 May 2011 18:44:06 +0000 (UTC) Received: from mx2.hub.org (mx2.hub.org [200.46.204.254]) by mail.postgresql.org (Postfix) with ESMTP id CDE141337C36 for ; Mon, 9 May 2011 15:07:36 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx2.hub.org (Postfix) with ESMTP id 58D993EAA821 for ; Mon, 9 May 2011 15:07:25 -0300 (ADT) Received: by wwc33 with SMTP id 33so5497781wwc.19 for ; Mon, 09 May 2011 11:06:36 -0700 (PDT) Received: by 10.227.62.207 with SMTP id y15mr4323966wbh.86.1304964395935; Mon, 09 May 2011 11:06:35 -0700 (PDT) Received: from mptpmbp.local (108-135.77-83.cust.bluewin.ch [83.77.135.108]) by mx.google.com with ESMTPS id bs4sm3908867wbb.18.2011.05.09.11.06.33 (version=SSLv3 cipher=OTHER); Mon, 09 May 2011 11:06:35 -0700 (PDT) Message-ID: <4DC82D28.7020105@engene.se> Date: Mon, 09 May 2011 20:06:32 +0200 From: Marcus Engene User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.16) Gecko/20101125 Thunderbird/3.0.11 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: wildcard makes seq scan on prod db but not in test Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-10 required=5 tests=BAYES_00=-1.9, NO_DNS_FOR_FROM=0.001 X-Spam-Level: X-Archive-Number: 201105/78 X-Sequence-Number: 43587 Dear list, I have a table with a few million rows and this index: CREATE INDEX bond_item_common_x7 ON bond_item_common ((lower(original_filename))); There are about 2M rows on bonddump and 4M rows on bond90. bonddump is on a 8MB RAM machine, bond90 is on a 72MB RAM machine. The table is analyzed properly both places. I'm an index hint zealot, but aware of our different stances in the matter. :) Dropping the wildcard for the like, both databases uses the index. Is there a way to convince Postgres to try not to do full table scan as much? This is just one of several examples when it happily spends lots of time sequentially going thru tables. Thanks, Marcus psql (9.0.4) Type "help" for help. bonddump=# explain analyze select pic2.objectid bonddump-# from bond_item_common pic2 bonddump-# where bonddump-# lower(pic2.original_filename) like 'this is a test%' ; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------- Index Scan using bond_item_common_x7 on bond_item_common pic2 (cost=0.01..8.69 rows=208 width=4) (actual time=26.415..26.415 rows=0 loops=1) Index Cond: ((lower((original_filename)::text) >= 'this is a test'::text) AND (lower((original_filename)::text) < 'this is a tesu'::text)) Filter: (lower((original_filename)::text) ~~ 'this is a test%'::text) Total runtime: 26.519 ms (4 rows) psql (9.0.4) bond90=> explain analyze select pic2.objectid bond90-> from bond_item_common pic2 bond90-> where bond90-> lower(pic2.original_filename) like 'this is a test%' ; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------ Seq Scan on bond_item_common pic2 (cost=0.00..839226.81 rows=475 width=4) (actual time=10599.401..10599.401 rows=0 loops=1) Filter: (lower((original_filename)::text) ~~ 'this is a test%'::text) Total runtime: 10599.425 ms (3 rows)