Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WBdlH-0006Mf-AY for pgsql-bugs@arkaria.postgresql.org; Fri, 07 Feb 2014 05:13:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WBdlG-00085E-P9 for pgsql-bugs@arkaria.postgresql.org; Fri, 07 Feb 2014 05:13:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WBdlF-00083y-FL for pgsql-bugs@postgresql.org; Fri, 07 Feb 2014 05:13:57 +0000 Received: from qmta14.westchester.pa.mail.comcast.net ([2001:558:fe14:44:76:96:59:212]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WBdlC-0003dB-E4 for pgsql-bugs@postgresql.org; Fri, 07 Feb 2014 05:13:57 +0000 Received: from omta02.westchester.pa.mail.comcast.net ([76.96.62.19]) by qmta14.westchester.pa.mail.comcast.net with comcast id PH7d1n0010QuhwU5EHDrWX; Fri, 07 Feb 2014 05:13:51 +0000 Received: from [10.59.1.101] ([83.80.19.126]) by omta02.westchester.pa.mail.comcast.net with comcast id PHDh1n00H2jCa9P3NHDkjt; Fri, 07 Feb 2014 05:13:49 +0000 Message-ID: <52F46B82.2000805@comcast.net> Date: Thu, 06 Feb 2014 21:13:38 -0800 From: Harry Rossignol User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: Re: BUG #9135: PostgreSQL doesn't want use index scan instead of (index scan+sort+limit) References: <20140207045518.13610.2870@wrigleys.postgresql.org> In-Reply-To: <20140207045518.13610.2870@wrigleys.postgresql.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20121106; t=1391750031; bh=ojprekPeMvBbpGKhThQai3301O6u9gm7Zizi83YIfks=; h=Received:Received:Message-ID:Date:From:MIME-Version:To:Subject: Content-Type; b=PXEGHj+AivlEqNr8ZbnUXXDxd5SF8eJxiE31fZR+zDVpt1LaNTbixeniWHCZAgiXG E7FR9lceZtjEyeM8v0D6znRyNA+92rl0aXfTk4aElkT84u8r3vm/QIAzjnEedQbqoF wbkG7dfasohGXAlBnrfVDEueIx5ntwttCNNefr1QgGfJd/wpawdmQg9uZA4OLrNGFp m7kNiQEcm2yqzof4PhRlJAYlFDQ1fqXTKX8eF1Ei5tMD2P5IfBE5WZdRsN4ZstGUtr y0QbSkVRfY+tAoTcEaAF+CvjQpnPzzLe0N5kxwGTS3l48jWU2mfHE/LkUYMEwB7lvA O9eReRO7h4iLg== X-Pg-Spam-Score: -1.3 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org I would try - select * from liexWebmasterProducts this_ where this_.lwpWebsiteI_.lwpnotForSale lwpWebsiteId,.lwpCreateDate desc limit 1; 2/6/2014 8:55 PM, maxim.boguk@gmail.com wrote: > The following bug has been logged on the website: > > Bug reference: 9135 > Logged by: Maxim Boguk > Email address: maxim.boguk@gmail.com > PostgreSQL version: 9.3.2 > Operating system: Linux > Description: > > Hi, > > One of my customers have very curious situation with simple query and index > usage. I tried different ideas but it doesn't work anyway and now I out of > ideas. It's looks like a bug if I not missing something. > > Detail: > 4GB liexWebmasterProducts table with interesting fields: > > lwpid | integer | not null > default nextval('liexwebmasterproducts_lwpid_seq'::regclass) > lwpname | text | > ... > lwpwebsiteid | integer | > ... > lwpnotforsale | boolean | not null > ... > lwpcreatedate | timestamp without time zone | not null > default now() > ... > > Index on the last three fields defined as: > "i_liexwebmasterproducts_2" btree (lwpwebsiteid, lwpnotforsale, > lwpcreatedate) > > Target query and plan: > select * > from liexWebmasterProducts this_ > where > this_.lwpWebsiteId=5935 > and this_.lwpnotForSale=FALSE > order by this_.lwpCreateDate desc limit 1; > > Limit (cost=122.18..122.19 rows=1 width=902) (actual time=13.505..13.506 > rows=1 loops=1) > -> Sort (cost=122.18..124.57 rows=953 width=902) (actual > time=13.503..13.503 rows=1 loops=1) > Sort Key: lwpcreatedate > Sort Method: top-N heapsort Memory: 27kB > -> Index Scan using i_liexwebmasterproducts_2 on > liexwebmasterproducts this_ (cost=0.43..117.42 rows=953 width=902) (actual > time=0.171..10.429 rows=1674 loops=1) > Index Cond: ((lwpwebsiteid = 5935) AND (lwpnotforsale = > false)) > Filter: (NOT lwpnotforsale) > Total runtime: 13.626 ms > > > I have no idea why Postgresql doesn't want use simple index scan over 3 > fields... > set enable_sort to 0; > have no effect: > > Limit (cost=10000000119.90..10000000119.90 rows=1 width=902) (actual > time=6.591..6.592 rows=1 loops=1) > -> Sort (cost=10000000119.90..10000000122.24 rows=935 width=902) > (actual time=6.588..6.588 rows=1 loops=1) > Sort Key: lwpcreatedate > Sort Method: top-N heapsort Memory: 27kB > -> Index Scan using i_liexwebmasterproducts_2 on > liexwebmasterproducts this_ (cost=0.43..115.22 rows=935 width=902) (actual > time=0.050..3.733 rows=1673 loops=1) > Index Cond: ((lwpwebsiteid = 5935) AND (lwpnotforsale = > false)) > Filter: (NOT lwpnotforsale) > Total runtime: 6.670 ms > > > It seems somehow related to the: "Filter: (NOT lwpnotforsale)" part of the > query which look like redundant, but it's my pure guessing. > > Reindexing the index, vacuum analyze table - provide zero effect on the > plan. > > Generating whole new subset and table via: > shop=# create table test as select lwpid,lwpwebsiteid, lwpnotforsale, > lwpcreatedate from liexwebmasterproducts; > SELECT 6799176 > shop=# create index CONCURRENTLY test_index_1 on test(lwpwebsiteid, > lwpnotforsale, lwpcreatedate); > CREATE INDEX > shop=# vacuum analyze test; > VACUUM > > Have no effect as well (plan over test table stay the same). > > Changing order of the two first fields in index via: > create index CONCURRENTLY test_index_2 on test(lwpnotforsale, lwpwebsiteid, > wpcreatedate); > have no effect on the plan too. > > Kindly Regards, > Maksym > > > > > -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs