Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 7E6821337C07 for ; Thu, 27 Jan 2011 16:32:04 -0400 (AST) 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 00539-03-4 for ; Thu, 27 Jan 2011 20:31:57 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from hrndva-omtalb.mail.rr.com (hrndva-omtalb.mail.rr.com [71.74.56.123]) by mail.postgresql.org (Postfix) with ESMTP id 3D50B1337BE4 for ; Thu, 27 Jan 2011 16:31:40 -0400 (AST) X-Authority-Analysis: v=1.1 cv=3uSaImBeuprzHBlOOPjkqgu+7PcxSRW0m2Aphm9Zmck= c=1 sm=0 a=xnPbYF9jDR4A:10 a=8nJEP1OIZ-IA:10 a=RAii6je2cdnAH6ATCOpc6g==:17 a=_Ixf_7qHAAAA:8 a=zNN3_TAQxsB9KtSw690A:9 a=LFMqFtgkPwNW9rfxoH8A:7 a=m4Pgt333jSh7Jy05EQkRGkgkziwA:4 a=wPNLvfGTeEIA:10 a=ryAo9hy1-OkA:10 a=6vsjEBoLwlAA:10 a=0tfO7MgyNwYA:10 a=RAii6je2cdnAH6ATCOpc6g==:117 X-Cloudmark-Score: 0 X-Originating-IP: 74.73.87.196 Received: from [74.73.87.196] ([74.73.87.196:51930] helo=[192.168.1.103]) by hrndva-oedge04.mail.rr.com (envelope-from ) (ecelerity 2.2.3.46 r()) with ESMTP id 0E/F4-04612-C26D14D4; Thu, 27 Jan 2011 20:31:40 +0000 Message-ID: <4D41D62C.40501@vmsinfo.com> Date: Thu, 27 Jan 2011 15:31:40 -0500 From: Mladen Gogala User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.13) Gecko/20101207 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: Igor Neyman CC: Tom Lane , David Wilson , Kenneth Marshall , "pgsql-performance@postgresql.org" Subject: Re: Postgres 9.0 has a bias against indexes References: <4D419214.8060003@vmsinfo.com> <20110127154539.GE6475@aart.is.rice.edu> <4D41959B.8020901@vmsinfo.com> <17268.1296146447@sss.pgh.pa.us> <4D41A496.70205@vmsinfo.com> In-Reply-To: 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.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201101/289 X-Sequence-Number: 42076 On 1/27/2011 3:10 PM, Igor Neyman wrote: > > Mladen, > > I don't think, this is exclusive Postgres feature. > I'm pretty sure, Oracle optimizer will do "TABLE ACCESS (FULL)" instead > of using index on 14-row table either. > > Regards, > Igor Neyman Well, lets' see: SQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production PL/SQL Release 11.2.0.2.0 - Production CORE 11.2.0.2.0 Production TNS for Linux: Version 11.2.0.2.0 - Production NLSRTL Version 11.2.0.2.0 - Production Elapsed: 00:00:00.00 SQL> set autotrace on explain SQL> with e(empno,ename,mgr,bossname,lev) as ( 2 select empno,ename,mgr,NULL,0 from emp where empno=7839 3 union all 4 select emp.empno,emp.ename,emp.mgr,e.ename,e.lev+1 5 from emp,e 6 where emp.mgr=e.empno) 7 select * from e 8 / EMPNO ENAME MGR BOSSNAME LEV ---------- ---------- ---------- ---------- ---------- 7839 KING 0 7566 JONES 7839 KING 1 7698 BLAKE 7839 KING 1 7782 CLARK 7839 KING 1 7499 ALLEN 7698 BLAKE 2 7521 WARD 7698 BLAKE 2 7654 MARTIN 7698 BLAKE 2 7788 SCOTT 7566 JONES 2 7844 TURNER 7698 BLAKE 2 7900 JAMES 7698 BLAKE 2 7902 FORD 7566 JONES 2 EMPNO ENAME MGR BOSSNAME LEV ---------- ---------- ---------- ---------- ---------- 7934 MILLER 7782 CLARK 2 7369 SMITH 7902 FORD 3 7876 ADAMS 7788 SCOTT 3 14 rows selected. Elapsed: 00:00:00.01 Execution Plan ---------------------------------------------------------- Plan hash value: 2925328376 -------------------------------------------------------------------------------- -------------------- | Id | Operation | Name | Rows | Bytes | Cos t (%CPU)| Time | -------------------------------------------------------------------------------- -------------------- | 0 | SELECT STATEMENT | | 15 | 795 | 6 (17)| 00:00:56 | | 1 | VIEW | | 15 | 795 | 6 (17)| 00:00:56 | | 2 | UNION ALL (RECURSIVE WITH) BREADTH FIRST| | | | | | | 3 | TABLE ACCESS BY INDEX ROWID | EMP | 1 | 24 | 1 (0)| 00:00:11 | |* 4 | INDEX UNIQUE SCAN | PK_EMP | 1 | | 0 (0)| 00:00:01 | |* 5 | HASH JOIN | | 14 | 798 | 5 (20)| 00:00:46 | | 6 | RECURSIVE WITH PUMP | | | | | | | 7 | TABLE ACCESS FULL | EMP | 14 | 336 | 3 (0)| 00:00:31 | -------------------------------------------------------------------------------- -------------------- Predicate Information (identified by operation id): --------------------------------------------------- 4 - access("EMPNO"=7839) 5 - access("EMP"."MGR"="E"."EMPNO") Note ----- - SQL plan baseline "SQL_PLAN_1tmxjj25531vff51d791e" used for this statement SQL> spool off There is INDEX UNIQUE SCAN PK_EMP. Oracle will use an index. -- Mladen Gogala Sr. Oracle DBA 1500 Broadway New York, NY 10036 (212) 329-5251 www.vmsinfo.com