Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TTCpP-0001wX-4c for pgsql-bugs@postgresql.org; Tue, 30 Oct 2012 14:30:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TTCpN-0003bX-8i for pgsql-bugs@postgresql.org; Tue, 30 Oct 2012 14:30:02 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q9UETuUi010947; Tue, 30 Oct 2012 10:29:56 -0400 (EDT) From: Tom Lane To: dmigowski@ikoffice.de cc: pgsql-bugs@postgresql.org Subject: Re: BUG #7629: Suboptimal query plan when index search is possible and an additional search operator is given. In-reply-to: References: Comments: In-reply-to dmigowski@ikoffice.de message dated "Tue, 30 Oct 2012 11:49:21 -0000" Date: Tue, 30 Oct 2012 10:29:56 -0400 Message-ID: <10946.1351607396@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201210/244 X-Sequence-Number: 34544 dmigowski@ikoffice.de writes: > However, when I also want to order by id: > order by prep_natural_sort(d.number) ASC, > d.id ASC > it does a sequential scan. Sure. That index doesn't satisfy this sort order. (It could have gotten chosen anyway, if the partial-index predicate were selective enough, but evidently it isn't.) > This is a bit stupid, also because the relevant data could be fetched very > fast by the first order-by expression, and then the results could be ordered > again, which is then much faster than doing a full sequential scan on the > data. That's an unsupported assertion, which we'd have to write a great deal of code before we could even test. There are a lot of more useful places to spend hacking time, with greater assurance of the work not being wasted. regards, tom lane