Outer Join and Index Usage
I am simply trying to run the following query:
select /*+ index (serialnumber trans) */ distinct device,
device_path||device hierarchy,
sn.serialnumber
from z_xfmr_levels z
left join serialnumber sn
on z.device = sn.transformergrid(+);
I am using Oracle 9i
z_xfmr_levels has 75,000 distinct rows
serialnumber has 204,000 distinct rows
The explain plan shows a hash join and a full table scan on both tables.
How can I get the query to use the index on the transformergrid field of the serialnumber table?
user10441616 wrote:
I am simply trying to run the following query:
select /*+ index (serialnumber trans) */ distinct device,
device_path||device hierarchy,
sn.serialnumber
from z_xfmr_levels z
left join serialnumber sn
on z.device = sn.transformergrid(+);
I am using Oracle 9i
z_xfmr_levels has 75,000 distinct rows
serialnumber has 204,000 distinct rows
The explain plan shows a hash join and a full table scan on both tables.
How can I get the query to use the index on the transformergrid field of the serialnumber table?What makes you think an index access is more appropriate than the the two full scans and a hash join?
If you have some legitimate reason, please share ... if not, please read this http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:9422487749968
Similar Messages
-
How to use left outer joins ,right outer joins and order by clause for belo
Hi,
How to use left outer joins ,right outer joins and order by clause for below XML query.
The query which is red colour returns null then its not displaying any values for columns in that tables. Tried decode, nvl function hasn't worked.
SELECT XMLAGG ( XMLELEMENT( "P", XMLFOREST( P.process_id AS Ppid,
(SELECT XMLAGG( XMLELEMENT( "PI", XMLFOREST( PI.question_id AS PIqid,
PI.process_id AS PIpid,
PI.innertext AS
PItext, PI.itemtype AS PItype,
PI.linkfrom AS PIfrom,
PI.linkto AS PIto,
PI.associated AS PIas,
PI.content_id AS PIc,
PI.exitpoint1_id AS PIe1,
PI.exitpoint2_id AS PIe2,
PI.exitpoint3_id AS PIe3,
PI.followoncall AS PIfoc,
PI.userinput AS PIui,
PI.resolveidentifier AS PIri,
PI.libquestion_idfk AS PIlqid,
PI.isLocked AS PIstls,
PI.PreviousAnswer AS PIPAns,
PI.VisibleToAgent AS PIVAgent,
PI.RetryAttempt AS PIRetry,
PI.Tags AS PITag,
SELECT XMLAGG( XMLELEMENT( "PO", XMLFOREST( PO.option_id AS POoid,
PO.question_id AS POqid,
PO.process_id AS popid,
PO.opt_innertext AS POtext,
PO.opt_linkfrom AS POfrom,
PO.opt_linkto AS POto,
PO.libquestion_idfk AS POlqid,
PO.liboption_idfk AS POloid ) ) )
FROM vw_liveProcessOption_Sim_v6 PO
WHERE PI.question_id = PO.question_id (+)
AND PI.process_id = PO.process_id (+)
) "A" ) ) ) AS "PO"
FROM vw_liveProcessItem_Sim_v6 PI
WHERE P.process_id = PI.process_id
) "A" ) ) ) AS "PI"
FROM liveProcess_ec P
WHERE (P.process_id = 450)
Any help really appreciated.
Thanksuser512743 wrote:
Hi,
Here below is the scripts of tables, insert statements and Required output.
CREATE TABLE VW_LIVEPROCESSOPTION_SIM_v6
( "OPTION_ID" NUMBER,
"QUESTION_ID" NUMBER(10,0),
"PROCESS_ID" NUMBER(10,0),
"OPT_INNERTEXT" VARCHAR2(200 CHAR),
"OPT_LINKFROM" VARCHAR2(20 CHAR),
"OPT_LINKTO" VARCHAR2(20 CHAR),
"LIBQUESTION_IDFK" NUMBER,
"LIBOPTION_IDFK" NUMBER
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,2,450,'Yes',null,'5',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,3,450,'Yes',null,'5',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,5,450,'Yes',null,'6',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,6,450,'Yes',null,'7',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,8,450,'Block All',null,'9',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,9,450,'Yes',null,'10',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,11,450,'Yes',null,'12',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,12,450,'Yes',null,'13',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,14,450,'Yes',null,'16',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,2,450,'No',null,'3',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,3,450,'No',null,'4',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,5,450,'No',null,'8',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,6,450,'No',null,'8',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,8,450,'Standard',null,'11',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,9,450,'No',null,'11',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,11,450,'No',null,'14',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,12,450,'No',null,'14',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,14,450,'No',null,'15',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (3,8,450,'Disabled',null,'12',null,null);
Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (4,8,450,'User Defined',null,'12',null,null);
REATE TABLE "VW_LIVEPROCESSITEM_SIM_v6"
( "QUESTION_ID" NUMBER(10,0),
"PROCESS_ID" NUMBER(10,0),
"INNERTEXT" VARCHAR2(200 CHAR),
"ITEMTYPE" VARCHAR2(50 CHAR),
"LINKFROM" VARCHAR2(500 CHAR),
"LINKTO" VARCHAR2(500 CHAR),
"ASSOCIATED" VARCHAR2(200 CHAR),
"CONTENT_ID" NUMBER,
"EXITPOINT1_ID" NUMBER(10,0),
"EXITPOINT2_ID" NUMBER(10,0),
"EXITPOINT3_ID" NUMBER(10,0),
"RESOLVEIDENTIFIER" VARCHAR2(40 CHAR),
"LIBQUESTION_IDFK" NUMBER(10,0),
"FOLLOWONCALL" NUMBER(1,0),
"USERINPUT" VARCHAR2(200 CHAR),
"ISLOCKED" NUMBER(1,0),
"PREVIOUSANSWER" NUMBER(1,0),
"VISIBLETOAGENT" NUMBER(1,0),
"RETRYATTEMPT" NUMBER(10,0),
"TAGS" VARCHAR2(50 BYTE)
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (1,450,'CBB1015 - Router Firewall Settinngs Process','Title',null,'2',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (2,450,'Is the customers PC Firewall turned off?','Question','1','2.2,2.1',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (3,450,'Advise the customer to turn off the PC Firewall in order to continue. Has this been done?','Question','2.2','3.2,3.1',null,278,null,null,null,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (4,450,'Advise the customer the PC Firewall must be switched off before this process????','ExitPoint','3.2',null,null,null,14,null,null,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (5,450,'Is the customer able to access the internet now?','Question','3.1,2.1','5.2,5.1',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (6,450,'Is the customer having a problem with a specific website?','Question','5.1','6.2,6.1',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (7,450,'1536: CBB1008 - Browser Setup and Daignostics','SubProcess','6.1',null,'1536-1-0',null,null,null,null,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (8,450,'What is the security level on the CPE Management page?','Question','6.2,5.2','8.4,8.3,8.2,8.1',null,279,null,null,null,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (9,450,'Change the security level to Standard. Does this resolve the customers issue?','Question','8.1','9.2,9.1',null,280,null,null,null,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (10,450,'Issue Resolved','ExitPoint','9.1',null,null,null,1,6,122,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (11,450,'Change the security level to Disabled. Is the customer able to browse the internet?','Question','9.2,8.2','11.2,11.1',null,281,null,null,null,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (12,450,'Change the security level to Standard. Is the customer able to browse the internet now?','Question','11.1,8.3,8.4','12.2,12.1',null,283,null,null,null,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (13,450,'Issue Resolved','ExitPoint','12.1',null,null,null,1,6,123,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (14,450,'Ask the customer to perform a master reset. Does this resolve their issue?','Question','12.2,11.2','14.2,14.1',null,282,null,null,null,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (15,450,'Faulty CPE','ExitPoint','14.2',null,null,null,1,6,124,null,null,null,null,null,null,null,null,null);
Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (16,450,'Issue Resolved','ExitPoint','14.1',null,null,null,1,6,123,null,null,null,null,null,null,null,null,null);
CREATE TABLE "LIVEPROCESS_EC_V"
( "PROCESS_ID" NUMBER(10,0),
"USER_ID" NUMBER(10,0),
"CREATED" TIMESTAMP (6)
Insert into LIVEPROCESS_EC (PROCESS_ID,USER_ID,CREATED) values (450,7460,to_timestamp('21-APR-08 09.34.41.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'));
Required O/P in XML format
<P>
<Ppid>450</Ppid>
<PI>
<PIqid>1</PIqid>
<PIpid>450</PIpid>
<PItext>CBB1015 - Router Firewall Settinngs Process</PItext>
<PItype>Title</PItype>
<PIto>2</PIto>
<PO />
</PI>
<PI>
<PIqid>2</PIqid>
<PIpid>450</PIpid>
<PItext>Is the customers PC Firewall turned off?</PItext>
<PItype>Question</PItype>
<PIfrom>1</PIfrom>
<PIto>2.2,2.1</PIto>
<PO>
<POoid>1</POoid>
<POqid>2</POqid>
<popid>450</popid>
<POtext>Yes</POtext>
<POto>5</POto>
</PO>
<PO>
<POoid>2</POoid>
<POqid>2</POqid>
<popid>450</popid>
<POtext>No</POtext>
<POto>3</POto>
</PO>
</PI>
<PI>
<PIqid>3</PIqid>
<PIpid>450</PIpid>
<PItext>Advise the customer to turn off the PC Firewall in order to continue. Has this been done?</PItext>
<PItype>Question</PItype>
<PIfrom>2.2</PIfrom>
<PIto>3.2,3.1</PIto>
<PIc>278</PIc>
<PO>
<POoid>1</POoid>
<POqid>3</POqid>
<popid>450</popid>
<POtext>Yes</POtext>
<POto>5</POto>
</PO>
<PO>
<POoid>2</POoid>
<POqid>3</POqid>
<popid>450</popid>
<POtext>No</POtext>
<POto>4</POto>
</PO>
</PI>
<PI>
<PIqid>4</PIqid>
<PIpid>450</PIpid>
<PItext>Advise the customer the PC Firewall must be switched off before this process????</PItext>
<PItype>ExitPoint</PItype>
<PIfrom>3.2</PIfrom>
<PIe1>14</PIe1>
<PO />
</PI>
<PI>
<PIqid>5</PIqid>
<PIpid>450</PIpid>
<PItext>Is the customer able to access the internet now?</PItext>
<PItype>Question</PItype>
<PIfrom>3.1,2.1</PIfrom>
<PIto>5.2,5.1</PIto>
<PO>
<POoid>1</POoid>
<POqid>5</POqid>
<popid>450</popid>
<POtext>Yes</POtext>
<POto>6</POto>
</PO>
<PO>
<POoid>2</POoid>
<POqid>5</POqid>
<popid>450</popid>
<POtext>No</POtext>
<POto>8</POto>
</PO>
</PI>
<PI>
<PIqid>6</PIqid>
<PIpid>450</PIpid>
<PItext>Is the customer having a problem with a specific website?</PItext>
<PItype>Question</PItype>
<PIfrom>5.1</PIfrom>
<PIto>6.2,6.1</PIto>
<PO>
<POoid>1</POoid>
<POqid>6</POqid>
<popid>450</popid>
<POtext>Yes</POtext>
<POto>7</POto>
</PO>
<PO>
<POoid>2</POoid>
<POqid>6</POqid>
<popid>450</popid>
<POtext>No</POtext>
<POto>8</POto>
</PO>
</PI>
<PI>
<PIqid>7</PIqid>
<PIpid>450</PIpid>
<PItext>1536: CBB1008 - Browser Setup and Daignostics</PItext>
<PItype>SubProcess</PItype>
<PIfrom>6.1</PIfrom>
<PIas>1536-1-0</PIas>
<PO />
</PI>
<PI>
<PIqid>8</PIqid>
<PIpid>450</PIpid>
<PItext>What is the security level on the CPE Management page?</PItext>
<PItype>Question</PItype>
<PIfrom>6.2,5.2</PIfrom>
<PIto>8.4,8.3,8.2,8.1</PIto>
<PIc>279</PIc>
<PO>
<POoid>1</POoid>
<POqid>8</POqid>
<popid>450</popid>
<POtext>Block All</POtext>
<POto>9</POto>
</PO>
<PO>
<POoid>2</POoid>
<POqid>8</POqid>
<popid>450</popid>
<POtext>Standard</POtext>
<POto>11</POto>
</PO>
<PO>
<POoid>3</POoid>
<POqid>8</POqid>
<popid>450</popid>
<POtext>Disabled</POtext>
<POto>12</POto>
</PO>
<PO>
<POoid>4</POoid>
<POqid>8</POqid>
<popid>450</popid>
<POtext>User Defined</POtext>
<POto>12</POto>
</PO>
</PI>
<PI>
<PIqid>9</PIqid>
<PIpid>450</PIpid>
<PItext>Change the security level to Standard. Does this resolve the customers issue?</PItext>
<PItype>Question</PItype>
<PIfrom>8.1</PIfrom>
<PIto>9.2,9.1</PIto>
<PIc>280</PIc>
<PO>
<POoid>1</POoid>
<POqid>9</POqid>
<popid>450</popid>
<POtext>Yes</POtext>
<POto>10</POto>
</PO>
<PO>
<POoid>2</POoid>
<POqid>9</POqid>
<popid>450</popid>
<POtext>No</POtext>
<POto>11</POto>
</PO>
</PI>
<PI>
<PIqid>10</PIqid>
<PIpid>450</PIpid>
<PItext>Issue Resolved</PItext>
<PItype>ExitPoint</PItype>
<PIfrom>9.1</PIfrom>
<PIe1>1</PIe1>
<PIe2>6</PIe2>
<PIe3>122</PIe3>
<PO />
</PI>
<PI>
<PIqid>11</PIqid>
<PIpid>450</PIpid>
<PItext>Change the security level to Disabled. Is the customer able to browse the internet?</PItext>
<PItype>Question</PItype>
<PIfrom>9.2,8.2</PIfrom>
<PIto>11.2,11.1</PIto>
<PIc>281</PIc>
<PO>
<POoid>1</POoid>
<POqid>11</POqid>
<popid>450</popid>
<POtext>Yes</POtext>
<POto>12</POto>
</PO>
<PO>
<POoid>2</POoid>
<POqid>11</POqid>
<popid>450</popid>
<POtext>No</POtext>
<POto>14</POto>
</PO>
</PI>
<PI>
<PIqid>12</PIqid>
<PIpid>450</PIpid>
<PItext>Change the security level to Standard. Is the customer able to browse the internet now?</PItext>
<PItype>Question</PItype>
<PIfrom>11.1,8.3,8.4</PIfrom>
<PIto>12.2,12.1</PIto>
<PIc>283</PIc>
<PO>
<POoid>1</POoid>
<POqid>12</POqid>
<popid>450</popid>
<POtext>Yes</POtext>
<POto>13</POto>
</PO>
<PO>
<POoid>2</POoid>
<POqid>12</POqid>
<popid>450</popid>
<POtext>No</POtext>
<POto>14</POto>
</PO>
</PI>
<PI>
<PIqid>13</PIqid>
<PIpid>450</PIpid>
<PItext>Issue Resolved</PItext>
<PItype>ExitPoint</PItype>
<PIfrom>12.1</PIfrom>
<PIe1>1</PIe1>
<PIe2>6</PIe2>
<PIe3>123</PIe3>
<PO />
</PI>
<PI>
<PIqid>14</PIqid>
<PIpid>450</PIpid>
<PItext>Ask the customer to perform a master reset. Does this resolve their issue?</PItext>
<PItype>Question</PItype>
<PIfrom>12.2,11.2</PIfrom>
<PIto>14.2,14.1</PIto>
<PIc>282</PIc>
<PO>
<POoid>1</POoid>
<POqid>14</POqid>
<popid>450</popid>
<POtext>Yes</POtext>
<POto>16</POto>
</PO>
<PO>
<POoid>2</POoid>
<POqid>14</POqid>
<popid>450</popid>
<POtext>No</POtext>
<POto>15</POto>
</PO>
</PI>
<PI>
<PIqid>15</PIqid>
<PIpid>450</PIpid>
<PItext>Faulty CPE</PItext>
<PItype>ExitPoint</PItype>
<PIfrom>14.2</PIfrom>
<PIe1>1</PIe1>
<PIe2>6</PIe2>
<PIe3>124</PIe3>
<PO />
</PI>
<PI>
<PIqid>16</PIqid>
<PIpid>450</PIpid>
<PItext>Issue Resolved</PItext>
<PItype>ExitPoint</PItype>
<PIfrom>14.1</PIfrom>
<PIe1>1</PIe1>
<PIe2>6</PIe2>
<PIe3>123</PIe3>
<PO />
</PI>
</P>
Thanks in advance
Edited by: user512743 on Nov 18, 2008 4:46 AM -
Hi,
I need to join three tables, based on some conditions (EKPO, EKBE and EKKN Note: All PO line items from EKPO will have a movement associated in the EKBE Table. Capture all PO line items where no matches found in the EKPO-EKBE join)
for the above requirement shall I write my query like this?
SELECT ekpo~ebeln
ekpo~ebelp
ekpo~loekz
ekpo~txz01
ekpo~matnr
ekpo~bukrs
ekpo~werks
ekpo~menge
ekpo~meins
ekpo~knttp
ekbe~vgabe
ekbe~bwart
ekbe~menge
ekbe~dmbtr
ekbe~shkzg
ekkn~sakto
ekkn~kostl
ekkn~ps_psp_pnr
INTO CORRESPONDING FIELDS OF TABLE i_podata
FROM ekpo LEFT OUTER JOIN ekbe ON ekbeebeln = ekpoebeln AND
ekbeebelp = ekpoebelp
INNER JOIN ekkn ON ekknebeln = ekpoebeln AND
ekknebelp = ekpoebelp
WHERE ekpo~werks IN s_werks AND
ekpo~ebeln IN s_ebeln.
Shall I use both Outer Join and Inner join in one Query?
Please correcte me.
Thanks
Frank RexHi,
You can use both inner join and outer join in the same select statement.
Ensure first all the inner joins between tables are declared and put the left outer join at the end.
Some sample code for your reference:
SELECT
AVBELN AKUNNR ABSTNK ABSTDK AVKORG AVTWEG AAUART AKNUMV
BPOSNR BMATNR BWERKS BSPART BLGORT BKZWI1
SUM( BKWMENG ) AS KWMENG DBZIRK D~VKGRP
EDISPO EPRCTR
FROM VBAK AS A INNER JOIN VBAP AS B ON AVBELN EQ BVBELN
INNER JOIN VBPA AS C ON CVBELN EQ BVBELN
INNER JOIN KNVV AS D ON DKUNNR EQ AKUNNR
AND DVKORG EQ AVKORG AND DVTWEG EQ AVTWEG
LEFT OUTER JOIN MARC AS E ON E~MATNR EQ
BMATNR AND EWERKS EQ B~WERKS
INTO CORRESPONDING FIELDS OF TABLE IT_ORDERS
WHERE A~VKORG IN SO_VKORG
AND A~VTWEG IN SO_VTWEG
AND A~KUNNR IN SO_KUNNR
AND A~ERDAT IN SO_ERDAT
AND A~AUART IN ('ZFOR','ZROR','ZEOR','ZDXR','ZXOR','ZRM1','ZGOR','ZSOR')
AND B~MATNR IN SO_MATNR
AND B~WERKS IN SO_WERKS
AND B~SPART IN SO_SPART
AND B~ABGRU EQ SPACE
AND A~LIFSK EQ SPACE
AND A~FAKSK EQ SPACE
AND B~VSTEL IN SO_VSTEL
AND B~LGORT IN SO_LGORT
AND C~KUNNR IN SO_SHIP
AND C~PARVW EQ 'WE'
AND D~VKGRP IN SO_VKGRP
AND D~BZIRK IN SO_BZIRK
AND B~LGORT NE '0950'
GROUP BY AVBELN AKUNNR ABSTNK ABSTDK
AVKORG AVTWEG AAUART AKNUMV B~POSNR
BMATNR BWERKS BSPART BKZWI1 D~BZIRK
DVKGRP BLGORT EDISPO EPRCTR E~MATGR.
Lakshminarayanan.
P.S.Mark all helpful answers for points. -
Script to find out table and index candidates to keep in the buffer pool
I am looking for a script to find out tables and indexes to keep in the buffer pool.
Could you help me on this ?
thanks...
Markusthis is more of a open question. As you know ur data well. We do not know whats ur data. cachin tables in buffer pool is okay, but it might age out after not being used...instead you can use the KEEP POOL...to cache small tables/popular tables into the keep pool...as keep pool guarantees full caching .....
here are some links on keep pool cacheing
http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/memory.htm#sthref410
http://www.dba-oracle.com/oracle_tips_cache_small_fts.htm
http://www.dba-oracle.com/t_script_automate_keep_pool_tables_indexes.htm
http://www.dba-oracle.com/oracle_news/news_caching_keep_pool_large_objects_clob_blob.htm
Edited by: user630084 on Apr 8, 2009 5:48 AM -
How to find out CPU and memory usage for an instance?
Hi DBA Gurus,
How to find out CPU usage and memory usage for an instance?
Any information is appreciated!
Thank you!
Robertyou can calculate cpu usage by adding fallowing three factors which you can get from v$sysstat
1. Parse CPU time : This represents the percentage of CPU time spent parsing SQL statements. Parse time CPU can be a strong indication that an application has not been well tuned. High parse time CPU usually indicates that the application may be spending too much time opening and closing cursors or is not using bind variables.
2. Recursive CPU time : Sometimes, to execute a SQL statement issued by a user, the Oracle Server must issue additional statements. Such statements are called recursive calls or recursive SQL statements. For example, if you insert a row into a table that does not have enough space to hold that row, the Oracle Server makes recursive calls to allocate the space dynamically if dictionary managed tablespaces are being used.
Recursive calls are also generated due to the inavailability of dictionary info in the dictionary cache, firing of database triggers, execution of DDL, execution of SQL within PL/SQL blocks, functions or stored procedures and enforcement of referential integrity constraints
3. Other CPU time : This represents the percentage of time spent looking for buffers, fetching rows or index keys, etc. Generally, \"Other\" CPU should represent the highest percentage of CPU time out of the total CPU time used.
total memory used you can calculate adding
total_agrigate_area+sga
memory usage on os level you can know by fallowing commands
vmstat 5 20 depending upon os -
Problem with outer joins and the class indicator/discriminator
Hello,
I am having a problem defining a query in toplink (10.1.3.3).
In the workbench, I have created a parent and 2 child descriptors. The parent is "AbstractValue", the children are "DefaultValue", classified by the discriminator 'DEF', and "OverrideValue", classified by 'OVR', both located in the same table.
Another descriptor (containing a one-on-one mapping to both a "DefaultValue", and a "OverrideValue") needs to be queried for its 'value'.
The way the query should act is: If an override value (row) exists, this one applies for that object. If an override doesn't exist, return the default value.
The query then comes down to (as I have it now):
builder.getAllowingNull("OverrideValue").getAllowingNull("value").ifNull(builder.get("DefaultValue").get("value")).equal(builder.getParameter(VALUE_PARAM));
The problem is that toplink adds the distinction for the different kind of "values" in the where clause WITHOUT checking for null values e.g. it performs an outer join, but then still checks for the discriminator value thus
....t1.ovr_id = t2.id(+) AND t2.discriminator = 'OVR' AND ...
instead of
... LEFT JOIN values t2 ON (t1.ovr_id = t2.id AND t2.discriminator = 'OVR') ...
This leads to the behaviour that the query returns ONLY the objects that have override and default values.
An overview of the queries (simplified)
Toplink, at the moment, returns only results if both override and default values exists:
SELECT t1.id
t1.def_id,
t1.ovr_id
FROM values t2,
parameter t1,
values t0
WHERE nvl(t2.value, t0.value) = 15 AND
t1.ovr_id = t2.id(+) AND t2.discriminator = 'OVR' AND
t1.def_id = t0.id AND t0.discriminator = 'DEF'
Situation Wanted:
SELECT t1.id
t1.def_id,
t1.ovr_id
FROM parameter t1
LEFT JOIN values t2 ON (t1.ovr_id = t2.id AND t2.discriminator = 'OVR')
JOIN values t0 ON (t1.def_id = t0.id AND t0.discriminator = 'DEF')
WHERE nvl(t2.value, t0.value) = 15
Anyone know if there is some statement I am missing to allow an actual outer join on descriptors containing class indicators/discriminators? A possible rewrite?
Thanks in advance,
RudyThis is a bug in TopLink's outer join support for Oracle. Currently the outer join is put in the where clause, instead of the from clause, as we do on other platforms. You might be able to fix it by changing your OraclePlatform to return false for shouldPrintOuterJoinInWhereClause().
Please log this bug on EclipseLink, or through Oracle technial support.
There is a workaround using,
descriptor.getInhertiancePolicy().setAlwaysUseOuterJoinForClassType(true);
James : http://www.eclipselink.org -
Rewrite the query with out joins and group by
Hi,
This was an interview question.
Table Names: bookshelf_checkout
bookshelf
And the join condition between these two tables is title
We need to rewrite below query without using join condition and group by clause ?
SELECT b.title,max(bc.returned_date - bc.checkout_date) "Most Days Out"
FROM bookshelf_checkout bc,bookshelf b
WHERE bc.title(+)=b.title
GROUP BY b.title;When I was in college, I read that most of the SELECT statements can be replaced by basic SQL operations (SET OPERATORS). Now I am trying to rewrite the query with SET operators but not able to get the exact result.
Kindly help me on this.
Thanks,
SuriSomething like this?
1 WITH books AS (
2 SELECT 'title 1' title FROM dual UNION ALL
3 SELECT 'title 2' FROM dual UNION ALL
4 SELECT 'title 3' FROM dual ),
5 bookshelf AS (
6 SELECT 'title 1' title, DATE '2012-05-01' checkout_date, DATE '2012-05-15' returned_date FROM dual UNION ALL
7 SELECT 'title 1' title, DATE '2012-05-16' checkout_date, DATE '2012-05-20' returned_date FROM dual UNION ALL
8 SELECT 'title 2' title, DATE '2012-04-01' checkout_date, DATE '2012-05-15' returned_date FROM dual )
9 SELECT bs.title, MAX(bs.returned_date - bs.checkout_date) OVER (PARTITION BY title) FROM bookshelf bs
10 UNION
11 (SELECT b.title, NULL FROM books b
12 MINUS
13* SELECT bs.title, NULL FROM bookshelf bs)
SQL> /
TITLE MAX(BS.RETURNED_DATE-BS.CHECKOUT_DATE)OVER(PARTITIONBYTITLE)
title 1 14
title 2 44
title 3Lukasz -
LIKE, LIKEC and Index usage
I've table that contains about 20 million rows, and I've created index for varchar2(100) column. It works well if I do
SELECT * FROM MY_TABLE WHERE MY_COL LIKE 'FOO%';
But if I change query to use LIKEC (to make unicode escaped strings work):
SELECT * FROM MY_TABLE WHERE MY_COL LIKEC 'FOO%';
I always get full table scan in explain plan.
I tried to use NVARCHAR, or index created by TO_NCHAR but I always end up hitting full table scan.
Should I create index some special way or do something else before I get index working?Just a gut feeling : is the database using character semantics or byte semantics?
My gut feeling, after looking up the documentation, is it should be character semantics.
BTW: Not posting version info decreases the chance you get an adequate reply.
Sybrand Bakker
Senior Oracle DBA -
Left outer join usage in obiee BMM layer
Hi All,
We lately started using left outer join in our bmm layer , to meet the requirement expectation .
problem : We have two tables Fact A , Dim B . There is an join int_id column to join them . Problem is... in table Dim B , we have 3 millions rows of Int_id and in fact table it is loaded for only data available(1 million rows).
Due to this we are dropping rows in the report ..as it is only getting data where fact.int_id = dim.int_id. So we used left outer join to solve to one particular report .(we know we can do ETl to load dummy int_id and make it null , but it is huge effort ..so we did left outer join)
These days , same kind of reports are in requirement . if i keep on doing same left outer join to meet the requirement in BMM layer ? is there any disadvantages due to this ? any performance degrade due to this ? please throw few lines on left outer join and its usage ?
Thanks,
SriRemodel your tables that might be a partition or any other way and follow in BI as per your new model.
Simply: Go for ETL kind of solution -
Performance Tunning - Connect By and Outer Join Used - Urgent
Hi,
I have written a query with the outer join and connect by prior since to establish the parent child relation ship.
All the tables having 2 lakhs record but the final result set is 20 thousand rows.
The query is taking 5 minutes to complete the execution. How could i improve the performance.
The query is
SELECT
'ABC' hrchy_id,
SUBSTR(c.abc_cd,1,1) ,
a.org_no bu_node_id,
SUBSTR(d.abc_cd,1,1) ,
a.prnt_org ,
level hrchy_lvl_nb,
a.eff_from_dt,
a.eff_to_dt,
FROM ((parent a INNER JOIN f_org b ON (a.org_no = b.org_no))
left join org c on ( (a.org_no = (c.abc_cd)))
) left join org d on ( (a.prnt_org = d.abc_cd)))
WHERE a.co_cd ='000'
START with a.prnt_org = '0'
CONNECT BY a.prnt_org = PRIOR a.org_no
ORDER SIBLINGS BY a.org_no;
Please suggest any idea or commands to improve the performance.
Thanks in advance.Can you provide the structure of tree based SQL.
Thanks in advance.But you have it already :-)
SELECT
'ABC' hrchy_id,
a.org_no bu_node_id,
a.prnt_org ,
level hrchy_lvl_nb,
a.eff_from_dt,
a.eff_to_dt,
FROM parent a WHERE a.co_cd ='000'
START with a.prnt_org = '0'
CONNECT BY a.prnt_org = PRIOR a.org_no
ORDER SIBLINGS BY a.org_no;Regards
Dmytro -
Sample code and senarios to use outer join?
We know the ABAP4 syntax for inner join, but never tried outer join and we even don't know if there is any outer join syntax in ABAP4 or not. Would be very appreciated if some ABAP expert here let us know if there is any outer join and list the difference between inner join and outer join with detailed senarios or when we would use outer join or when to use inner join? Also give a sample code on the outer join if there is any in ABAP?
Thanks and we will give you reward points!Hye..
Left outer join between table 1 and table 2 where column D in both tables set the join condition:
Table 1 Table 2
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
3
e2
f2
g2
h2
a3
b3
c3
2
4
e3
f3
g3
h3
a4
b4
c4
3
|--|||--|
Left Outer Join
|--||||||||--|
| A | B | C | D | D | E | F | G | H |
|--||||||||--|
| a1 | b1 | c1 | 1 | 1 | e1 | f1 | g1 | h1 |
| a2 | b2 | c2 | 1 | 1 | e1 | f1 | g1 | h1 |
| a3 | b3 | c3 | 2 |NULL|NULL|NULL|NULL|NULL|
| a4 | b4 | c4 | 3 | 3 | e2 | f2 | g2 | h2 |
|--||||||||--|
Example
Output a list of all custimers with their bookings for October 15th, 2001:
DATA: CUSTOMER TYPE SCUSTOM,
BOOKING TYPE SBOOK.
SELECT SCUSTOMNAME SCUSTOMPOSTCODE SCUSTOM~CITY
SBOOKFLDATE SBOOKCARRID SBOOKCONNID SBOOKBOOKID
INTO (CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID)
FROM SCUSTOM LEFT OUTER JOIN SBOOK
ON SCUSTOMID = SBOOKCUSTOMID AND
SBOOK~FLDATE = '20011015'
ORDER BY SCUSTOMNAME SBOOKFLDATE.
WRITE: / CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID.
ENDSELECT.
Reward if helpful.
Thanks.
Imran. -
Inner join and outer join in infosets
hi everyone,
i have a doubt in infosets...
when and why we use inner and outer joins(right outer join and left outer join) for infoset
please give a real time scenario........
Thanks in advance.
Bye.Hello,
Inner join:
For example, the requirement is to show all sales documents where you have delivery exists. In this case, you join both sales ods and delivery ods in a infoset as inner join. This will match the record against the reference documents and pull only matched records.
Outer Join:
Suppose you want to pull all billing/invoice details along with their FI documents related data in a report. Assume that always there might be a situation that invoice exists but not posted to FI, however, you want to have all billing documents details either it has FI document or not. In this case, you link both Billing data and FI document data in a outer join. This will pull all invoices data either FI document exists or not. Other words, you want to show one side of data always but adding additional details from differenent source if data exists.
Hope, it clarifies your doubt. Let me know if any questions.
Thanks
Viswa -
I need to select records, one for each index having a list of column pairs indicating column name and id.
An index may have one or more columns (obviously).
I'll need one record from user_indexes, at least one record from user_ind_columns for which I will have one corresponding record from user_tab_columns.
Example output:
table_name, index_name, column_name, column_id, column_name, column_id ...
I wrote what looked like the correct syntax (unfortunately, Oracle's meta data is not normalized):
select i.table_name, i.index_name,
c1.column_name, c1.column_id,
c2.column_name, c2.column_id,
c3.column_name, c3.column_id
from used_indexes i,
user_ind_columns ic1, user_tab_columns c1,
user_ind_columns ic2, user_tab_columns c2,
user_ind_columns ic3, user_tab_columns c3
where i.uniqueness='UNIQUE'
and i.table_name = 'CUST'
and i.table_name = ic1.table_name
and i.index_name = ic1.index_name
and ic1.table_name = c1.table_name
and ic1.column_name = c1.column_name
and ic1.column_position = 1
and i.table_name = ic2.table_name(+)
and i.index_name = ic2.index_name(+)
and ic2.column_name = c2.column_name
and ic2.table_name = c2.table_name
and ic2.column_position = 2
and i.table_name = ic3.table_name(+)
and i.index_name = ic3.index_name(+)
and ic3.column_name = c3.column_name
and ic3.table_name = c3.table_name
and ic3.column_position = 3
This query seems to 'hang' in SQL*Plus not returning any results or errors... EVER! Any ideas as to what the problem might be? Any suggestions as to how to create this query in a more suportable way? I will have to extend this to include up to 10 index fields for each index.
Thanks,
JimI am not sure if this does what you want, but it is syntactically correct and runs.
select i.table_name, i.index_name,c1.column_name, c1.column_id,c2.column_name, c2.column_id
from user_indexes i
left outer join user_ind_columns ic2
on i.table_name = ic2.table_name
and i.index_name = ic2.index_name
inner join user_tab_columns c2
on ic2.table_name = c2.table_name
and ic2.column_name = c2.column_name
left outer join user_ind_columns ic1
on i.table_name = ic1.table_name
and i.index_name = ic1.index_name
inner join user_tab_columns c1
on ic1.table_name = c1.table_name
and ic1.column_name = c1.column_name
where i.uniqueness='UNIQUE'
and ic1.column_position = 1
and ic2.column_position = 2
order by 1,2However I don't think you are approaching this the right way. How can you be sure you aren't going to miss an index column? You have to add 2 tables an inner and outer join and a where predicate for each column you want to capture. That could get silly. There is at least one index on 5 columns in the Oacle dictionary and I have encountered larger indexes.
This query captures everything. You just need to do a bit of procedural work to turn it into create index statements or whatever you are after.
select i.table_name, i.index_name,c2.column_name, c2.column_id, ic2.column_position
from user_indexes i
inner join user_ind_columns ic2
on i.table_name = ic2.table_name
and i.index_name = ic2.index_name
inner join user_tab_columns c2
on ic2.table_name = c2.table_name
and ic2.column_name = c2.column_name
where i.uniqueness='UNIQUE'
order by i.table_name, i.index_name,ic2.column_position
</pre] -
Dear All,
Please help me in tuning the below query as it is including the outer join and is going for full table scans.
Query :
SELECT
T27.CONFLICT_ID,
T27.LAST_UPD,
T27.CREATED,
T27.LAST_UPD_BY,
T27.CREATED_BY,
T27.MODIFICATION_NUM,
T27.ROW_ID,
T24.ATTRIB_39,
T27.REMIT_ADDR_ORG_ID,
T27.REMIT_ORG_EXT_ID,
T16.NAME,
T25.ACCNT_TYPE_CD,
T27.RECAL_TAX_SRV_FLG,
T27.PROJ_ID,
T8.PROJ_NUM,
T8.BU_ID,
T5.NAME,
T8.INTEGRATION_ID,
T12.CURCY_CD,
T25.PR_BL_ADDR_ID,
T25.URL,
T27.TTL_INVC_AMT,
T27.INVC_TYPE_CD,
T27.TTL_PD_AMT,
T3.CG_ASSSET_ID,
T17.ASSET_NUM,
T27.VENDR_INVOICE_NUM,
T4.TOT_QTY_SHIP,
T4.TOT_EXTND_PRICE,
T27.ACCNT_ID,
T25.INTEGRATION_ID,
T25.NAME,
T25.BU_ID,
T25.AVAIL_CREDIT_AMT,
T10.NAME,
T27.AGREEMENT_ID,
T4.TOT_EXTND_TAX,
T27.STMT_SOURCE_CD,
T4.SRC_INVLOC_ID,
T27.STATUS_CD,
T4.TOT_QTY_BONUS,
T27.X_DEPOSIT_AMT,
T27.COMMENTS,
T27.INVC_FULLY_PAID_DT,
T26.SEQ_NUM,
T27.ELEMENT_ID,
T26.INSCLM_ID,
T14.INSCLAIM_NUM,
T27.BL_PER_ID,
T27.INS_CLAIM_ID,
T27.FN_ACCNT_ID,
T27.CUSTOMER_REF_NUM,
T27.TTL_NONREC_AMT,
T25.OU_NUM,
T24.ATTRIB_39,
T27.AMT_CURCY_CD,
T2.CCNUM_ENCRPKEY_REF,
T18.PR_DEPOSIT_ID,
T19.DISCNT_RULE_CD,
T27.ORDER_ID,
T4.STATUS_CHG_FLG,
T25.MAIN_PH_NUM,
T25.MAIN_FAX_PH_NUM,
T27.DELINQUENT_FLG,
T15.LOGIN,
T25.PR_POSTN_ID,
T4.ORDER_NUM,
T22.ADDR,
T22.ZIPCODE,
T27.INVC_NUM,
T27.INVC_DT,
T22.COUNTRY,
T22.CITY,
T27.BL_ADDR_ID,
T23.NAME,
T27.POSTED_DT,
T20.NAME,
T27.BL_PERIOD_ID,
T27.GOODS_DLVRD_TS,
T23.NET_DAYS,
T27.PAYMENT_TERM_ID,
T23.DUE_DT,
T27.DUE_DT,
T27.VOID_REASON_TEXT,
T27.DEPT_CD,
T24.ATTRIB_60,
T24.ATTRIB_28,
T21.AMT,
T1.STATE,
T1.ADDR,
T1.ADDR_LINE_2,
T1.COUNTRY,
T1.CITY,
T1.ZIPCODE,
T11.LOGIN,
T21.ROW_ID,
T9.ROW_ID,
T1.ROW_ID,
T13.ROW_ID,
T7.ROW_ID
FROM
SIEBEL.S_ADDR_PER T1,
SIEBEL.S_PTY_PAY_PRFL T2,
SIEBEL.S_INVLOC T3,
SIEBEL.S_ORDER T4,
SIEBEL.S_ORG_EXT T5,
SIEBEL.S_POSTN T6,
SIEBEL.S_PARTY T7,
SIEBEL.S_PROJ T8,
SIEBEL.S_CON_ADDR T9,
SIEBEL.S_ORG_EXT T10,
SIEBEL.S_USER T11,
SIEBEL.S_DOC_QUOTE T12,
SIEBEL.S_ACCNT_POSTN T13,
SIEBEL.S_INS_CLAIM T14,
SIEBEL.S_USER T15,
SIEBEL.S_ORG_EXT T16,
SIEBEL.S_ASSET T17,
SIEBEL.S_ORDER_TNTX T18,
SIEBEL.S_ORG_EXT_TNTX T19,
SIEBEL.S_PERIOD T20,
SIEBEL.S_DEPOSIT_TNT T21,
SIEBEL.S_ADDR_PER T22,
SIEBEL.S_PAYMENT_TERM T23,
SIEBEL.S_ORG_EXT_X T24,
SIEBEL.S_ORG_EXT T25,
SIEBEL.S_INSCLM_ELMNT T26,
SIEBEL.S_INVOICE T27
WHERE
T25.BU_ID = T10.PAR_ROW_ID (+) AND
T26.INSCLM_ID = T14.ROW_ID (+) AND
T27.ELEMENT_ID = T26.ROW_ID (+) AND
T27.LAST_UPD_BY = T15.PAR_ROW_ID (+) AND
T4.QUOTE_ID = T12.ROW_ID (+) AND
T3.CG_ASSSET_ID = T17.ROW_ID (+) AND
T27.BL_ADDR_ID = T22.ROW_ID (+) AND
T8.BU_ID = T5.PAR_ROW_ID (+) AND
T27.PER_PAY_PRFL_ID = T2.ROW_ID (+) AND
T27.REMIT_ORG_EXT_ID = T16.PAR_ROW_ID (+) AND
T27.PROJ_ID = T8.ROW_ID (+) AND
T27.BL_PERIOD_ID = T20.ROW_ID (+) AND
T27.PAYMENT_TERM_ID = T23.ROW_ID (+) AND
T12.BU_ID = T19.PAR_ROW_ID (+) AND
T27.ACCNT_ID = T25.PAR_ROW_ID (+) AND
T27.ORDER_ID = T18.ROW_ID (+) AND
T4.SRC_INVLOC_ID = T3.ROW_ID (+) AND
T27.ORDER_ID = T4.ROW_ID (+) AND
T27.ACCNT_ID = T24.PAR_ROW_ID (+) AND
T18.PR_DEPOSIT_ID = T21.ROW_ID (+) AND
T27.BL_ADDR_ID = T9.ADDR_PER_ID (+) AND
T27.ACCNT_ID = T9.ACCNT_ID (+) AND
T27.BL_ADDR_ID = T1.ROW_ID (+) AND
T25.PR_POSTN_ID = T13.POSITION_ID (+) AND
T25.ROW_ID = T13.OU_EXT_ID (+) AND
T13.POSITION_ID = T7.ROW_ID (+) AND
T13.POSITION_ID = T6.PAR_ROW_ID (+) AND
T6.PR_EMP_ID = T11.PAR_ROW_ID (+) AND
(T27.INVC_TYPE_CD = :1) AND
(T27.DEPT_CD = :2);
Explan Plan Output :
PLAN_TABLE_OUTPUT
Plan hash value: 3132260827
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 1958 | 1896K (11)| 00:50:46 |
| 1 | NESTED LOOPS OUTER | | 1 | 1958 | 1896K (11)| 00:50:46 |
| 2 | NESTED LOOPS OUTER | | 1 | 1922 | 1896K (11)| 00:50:46 |
| 3 | NESTED LOOPS OUTER | | 1 | 1885 | 1896K (11)| 00:50:46 |
| 4 | NESTED LOOPS OUTER | | 1 | 1861 | 1896K (11)| 00:50:46 |
| 5 | NESTED LOOPS OUTER | | 1 | 1849 | 1896K (11)| 00:50:46 |
| 6 | NESTED LOOPS OUTER | | 1 | 1817 | 1896K (11)| 00:50:46 |
| 7 | NESTED LOOPS OUTER | | 1 | 1792 | 1896K (11)| 00:50:46 |
| 8 | NESTED LOOPS OUTER | | 1 | 1771 | 1896K (11)| 00:50:46 |
| 9 | NESTED LOOPS OUTER | | 1 | 1739 | 1896K (11)| 00:50:46 |
| 10 | NESTED LOOPS OUTER | | 1 | 1483 | 1896K (11)| 00:50:46 |
| 11 | NESTED LOOPS OUTER | | 1 | 1451 | 1896K (11)| 00:50:46 |
| 12 | NESTED LOOPS OUTER | | 1 | 1419 | 1896K (11)| 00:50:46 |
| 13 | NESTED LOOPS OUTER | | 1 | 1361 | 1896K (11)| 00:50:46 |
| 14 | NESTED LOOPS OUTER | | 1 | 1276 | 1896K (11)| 00:50:46 |
| 15 | NESTED LOOPS OUTER | | 1 | 1202 | 1896K (11)| 00:50:46 |
| 16 | NESTED LOOPS OUTER | | 1 | 1108 | 1896K (11)| 00:50:46 |
| 17 | NESTED LOOPS OUTER | | 1 | 1087 | 1896K (11)| 00:50:46 |
| 18 | NESTED LOOPS OUTER | | 1 | 1040 | 1896K (11)| 00:50:46 |
| 19 | NESTED LOOPS OUTER | | 1 | 939 | 1896K (11)| 00:50:46 |
| 20 | NESTED LOOPS OUTER | | 1 | 894 | 1896K (11)| 00:50:46 |
| 21 | NESTED LOOPS OUTER | | 1 | 868 | 1896K (11)| 00:50:46 |
| 22 | NESTED LOOPS OUTER | | 1 | 843 | 1896K (11)| 00:50:46 |
| 23 | NESTED LOOPS OUTER | | 1 | 824 | 1896K (11)| 00:50:46 |
| 24 | NESTED LOOPS OUTER | | 1 | 690 | 1896K (11)| 00:50:46 |
| 25 | NESTED LOOPS OUTER | | 1 | 613 | 1896K (11)| 00:50:46 |
| 26 | NESTED LOOPS OUTER | | 1 | 457 | 1896K (11)| 00:50:46 |
|* 27 | TABLE ACCESS FULL | S_INVOICE | 1 | 269 | 1896K (11)| 00:50:46 |
| 28 | TABLE ACCESS BY INDEX ROWID| S_PROJ | 1 | 188 | 1 (0)| 00:00:01 |
|* 29 | INDEX UNIQUE SCAN | S_PROJ_P1 | 1 | | 1 (0)| 00:00:01 |
| 30 | TABLE ACCESS BY INDEX ROWID | S_PAYMENT_TERM | 1 | 156 | 1 (0)| 00:00:01 |
|* 31 | INDEX UNIQUE SCAN | S_PAYMENT_TERM_P1 | 1 | | 1 (0)| 00:00:01 |
| 32 | TABLE ACCESS BY INDEX ROWID | S_INSCLM_ELMNT | 1 | 77 | 1 (0)| 00:00:01 |
|* 33 | INDEX UNIQUE SCAN | S_INSCLM_ELMNT_P1 | 1 | | 1 (0)| 00:00:01 |
| 34 | TABLE ACCESS BY INDEX ROWID | S_INS_CLAIM | 1 | 134 | 1 (0)| 00:00:01 |
|* 35 | INDEX UNIQUE SCAN | S_INS_CLAIM_P1 | 1 | | 1 (0)| 00:00:01 |
| 36 | TABLE ACCESS BY INDEX ROWID | S_PERIOD | 1 | 19 | 1 (0)| 00:00:01 |
|* 37 | INDEX UNIQUE SCAN | S_PERIOD_P1 | 1 | | 1 (0)| 00:00:01 |
| 38 | TABLE ACCESS BY INDEX ROWID | S_USER | 1 | 25 | 2 (0)| 00:00:01 |
|* 39 | INDEX UNIQUE SCAN | S_USER_U2 | 1 | | 1 (0)| 00:00:01 |
| 40 | TABLE ACCESS BY INDEX ROWID | S_ORDER_TNTX | 1 | 26 | 2 (0)| 00:00:01 |
|* 41 | INDEX UNIQUE SCAN | S_ORDER_TNTX_P1 | 1 | | 1 (0)| 00:00:01 |
| 42 | TABLE ACCESS BY INDEX ROWID | S_DEPOSIT_TNT | 1 | 45 | 1 (0)| 00:00:01 |
|* 43 | INDEX UNIQUE SCAN | S_DEPOSIT_TNT_P1 | 1 | | 1 (0)| 00:00:01 |
| 44 | TABLE ACCESS BY INDEX ROWID | S_ORDER | 1 | 101 | 2 (0)| 00:00:01 |
|* 45 | INDEX UNIQUE SCAN | S_ORDER_P1 | 1 | | 1 (0)| 00:00:01 |
| 46 | TABLE ACCESS BY INDEX ROWID | S_INVLOC | 1 | 47 | 1 (0)| 00:00:01 |
|* 47 | INDEX UNIQUE SCAN | S_INVLOC_P1 | 1 | | 1 (0)| 00:00:01 |
| 48 | TABLE ACCESS BY INDEX ROWID | S_DOC_QUOTE | 1 | 21 | 1 (0)| 00:00:01 |
|* 49 | INDEX UNIQUE SCAN | S_DOC_QUOTE_P1 | 1 | | 1 (0)| 00:00:01 |
| 50 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT_TNTX | 1 | 94 | 1 (0)| 00:00:01 |
|* 51 | INDEX RANGE SCAN | S_ORG_EXT_TNTX_U1 | 1 | | 1 (0)| 00:00:01 |
| 52 | TABLE ACCESS BY INDEX ROWID | S_PTY_PAY_PRFL | 1 | 74 | 1 (0)| 00:00:01 |
|* 53 | INDEX UNIQUE SCAN | S_PTY_PAY_PRFL_P1 | 1 | | 1 (0)| 00:00:01 |
| 54 | TABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1 | 85 | 2 (0)| 00:00:01 |
|* 55 | INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | 1 (0)| 00:00:01 |
| 56 | TABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1 | 58 | 1 (0)| 00:00:01 |
|* 57 | INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | 1 (0)| 00:00:01 |
| 58 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 32 | 1 (0)| 00:00:01 |
|* 59 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0)| 00:00:01 |
| 60 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 32 | 1 (0)| 00:00:01 |
|* 61 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0)| 00:00:01 |
| 62 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 256 | 2 (0)| 00:00:01 |
|* 63 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0)| 00:00:01 |
| 64 | TABLE ACCESS BY INDEX ROWID | S_ACCNT_POSTN | 1 | 32 | 3 (0)| 00:00:01 |
|* 65 | INDEX RANGE SCAN | S_ACCNT_POSTN_U1 | 1 | | 2 (0)| 00:00:01 |
| 66 | TABLE ACCESS BY INDEX ROWID | S_POSTN | 1 | 21 | 1 (0)| 00:00:01 |
|* 67 | INDEX UNIQUE SCAN | S_POSTN_U2 | 1 | | 1 (0)| 00:00:01 |
| 68 | TABLE ACCESS BY INDEX ROWID | S_USER | 1 | 25 | 2 (0)| 00:00:01 |
|* 69 | INDEX UNIQUE SCAN | S_USER_U2 | 1 | | 1 (0)| 00:00:01 |
| 70 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 32 | 2 (0)| 00:00:01 |
|* 71 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0)| 00:00:01 |
|* 72 | INDEX UNIQUE SCAN | S_PARTY_P1 | 1 | 12 | 1 (0)| 00:00:01 |
| 73 | TABLE ACCESS BY INDEX ROWID | S_ASSET | 1 | 24 | 2 (0)| 00:00:01 |
|* 74 | INDEX UNIQUE SCAN | S_ASSET_P1 | 1 | | 2 (0)| 00:00:01 |
| 75 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT_X | 1 | 37 | 2 (0)| 00:00:01 |
|* 76 | INDEX RANGE SCAN | S_ORG_EXT_X_U1 | 1 | | 2 (0)| 00:00:01 |
| 77 | TABLE ACCESS BY INDEX ROWID | S_CON_ADDR | 1 | 36 | 3 (0)| 00:00:01 |
|* 78 | INDEX RANGE SCAN | S_CON_ADDR_U1 | 1 | | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
27 - filter("T27"."DEPT_CD"=:2 AND "T27"."INVC_TYPE_CD"=:1)
29 - access("T27"."PROJ_ID"="T8"."ROW_ID"(+))
31 - access("T27"."PAYMENT_TERM_ID"="T23"."ROW_ID"(+))
33 - access("T27"."ELEMENT_ID"="T26"."ROW_ID"(+))
35 - access("T26"."INSCLM_ID"="T14"."ROW_ID"(+))
37 - access("T27"."BL_PERIOD_ID"="T20"."ROW_ID"(+))
39 - access("T27"."LAST_UPD_BY"="T15"."PAR_ROW_ID"(+))
41 - access("T27"."ORDER_ID"="T18"."ROW_ID"(+))
43 - access("T18"."PR_DEPOSIT_ID"="T21"."ROW_ID"(+))
45 - access("T27"."ORDER_ID"="T4"."ROW_ID"(+))
47 - access("T4"."SRC_INVLOC_ID"="T3"."ROW_ID"(+))
49 - access("T4"."QUOTE_ID"="T12"."ROW_ID"(+))
51 - access("T12"."BU_ID"="T19"."PAR_ROW_ID"(+))
53 - access("T27"."PER_PAY_PRFL_ID"="T2"."ROW_ID"(+))
55 - access("T27"."BL_ADDR_ID"="T1"."ROW_ID"(+))
57 - access("T27"."BL_ADDR_ID"="T22"."ROW_ID"(+))
59 - access("T8"."BU_ID"="T5"."PAR_ROW_ID"(+))
61 - access("T27"."REMIT_ORG_EXT_ID"="T16"."PAR_ROW_ID"(+))
63 - access("T27"."ACCNT_ID"="T25"."PAR_ROW_ID"(+))
65 - access("T25"."ROW_ID"="T13"."OU_EXT_ID"(+) AND "T25"."PR_POSTN_ID"="T13"."POSITION_ID"(+))
67 - access("T13"."POSITION_ID"="T6"."PAR_ROW_ID"(+))
69 - access("T6"."PR_EMP_ID"="T11"."PAR_ROW_ID"(+))
71 - access("T25"."BU_ID"="T10"."PAR_ROW_ID"(+))
72 - access("T13"."POSITION_ID"="T7"."ROW_ID"(+))
74 - access("T3"."CG_ASSSET_ID"="T17"."ROW_ID"(+))
76 - access("T27"."ACCNT_ID"="T24"."PAR_ROW_ID"(+))
78 - access("T27"."BL_ADDR_ID"="T9"."ADDR_PER_ID"(+) AND "T27"."ACCNT_ID"="T9"."ACCNT_ID"(+))
filter("T27"."ACCNT_ID"="T9"."ACCNT_ID"(+))
117 rows selected.
We are using 10.2.0.3 oracle version.Hi
according to the explain plan, > 99% of the cost of the query is coming from a single operation -- step 27, full scan of S_INVOICE table.
This probably means that there are no usable indexes on DEPT_CD and/or INVC_TYPE_CD.
So start by tuning SELECT * FROM S_INVOICE T27 WHERE ("T27"."DEPT_CD"=:2 AND "T27"."INVC_TYPE_CD"=:1)
BTW the plan shows that 1 row is to be returned, while Oracle actually returns 117 -- this means that the optimizer estimates are not very reliable here.
Best regards,
Nikolay -
Outer join vs. 'SELECT in SELECT'
Hi All,
I am generally curious about which method to use between a Outer join and 'SELECT in SELECT'. We can have same result with both methods.
My question is, for real life complex queries, which method is more efficiant? less resource intensive? Any thories you guys have?
I am on Oracle 10.2 on lunix.
See my example below
-- First table
create table emp
id number,
name varchar2(1000),
constraint emp_pk primary key ( id )
-- second table. There will be 1 record, for few of the records in EMP table, in this table
create table leave
id number,
emp_id number,
leave_date date,
constraint leave_pk primary key (id),
constraint leave_fk foreign key ( emp_id ) references emp
create index leave_idx_1 on leave ( emp_id ) ;
-- Populate some sample data in there
insert into emp (id, name)
select object_id, object_name from dba_objects where rownum < 10001 ;
declare
cursor c1 is
select id from emp where mod(id,2) = 0 ;
v_id number := 1 ;
v_date DATE := '01-JAN-08';
begin
for c2 in c1
loop
insert into leave values ( v_id, c2.id, v_date );
v_id := v_id + 1;
v_date := v_date + 1;
end loop;
end;
-- Set autotrace
set autotrace traceonly explain
-- =================================
-- Outer join
-- =================================
select e.id, e.name, l.id, l.leave_date
from emp e, leave l
where e.id = l.emp_id (+) ;
-- ===================================
-- select in select to get same results as above outer join
-- ===================================
select e.id, e.name,
(select l.id from leave l where l.emp_id = e.id ) leave_id,
(select l.leave_date from leave l where l.emp_id = e.id ) leave_date
from emp e ;My hidden question, how these two methods internally work? in the plan we can only see something like 'hash join right outer' or something like that. But how exactly outer join is executed? how is the result formed?
I have got following plans for the two methods
SQL> select e.id, e.name, l.id, l.leave_date
2 from emp e, leave l
3 where e.id = l.emp_id (+) ;
Elapsed: 00:00:00.03
Execution Plan
Plan hash value: 98076489
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 10000 | 5371K| 16 (7)| 00:00:01 |
|* 1 | HASH JOIN RIGHT OUTER| | 10000 | 5371K| 16 (7)| 00:00:01 |
| 2 | TABLE ACCESS FULL | LEAVE | 5012 | 171K| 6 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL | EMP | 10000 | 5029K| 9 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - access("E"."ID"="L"."EMP_ID"(+))
Note
- dynamic sampling used for this statement
SQL> select e.id, e.name,
2 (select l.id from leave l where l.emp_id = e.id ) leave_id,
3 (select l.leave_date from leave l where l.emp_id = e.id ) leave_date
4 from emp e ;
Elapsed: 00:00:00.18
Execution Plan
Plan hash value: 2670217481
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 10000 | 5029K| 9 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| LEAVE | 50 | 1300 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | LEAVE_IDX_1 | 20 | | 1 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID| LEAVE | 50 | 1100 | 2 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | LEAVE_IDX_1 | 20 | | 1 (0)| 00:00:01 |
| 5 | TABLE ACCESS FULL | EMP | 10000 | 5029K| 9 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("L"."EMP_ID"=:B1)
4 - access("L"."EMP_ID"=:B1)
Note
- dynamic sampling used for this statementPlease let me know your thoughts.
Thanks in advanceA better indicator of performance would be to look at the number of consistent gets that are required to execute the query.
In my environment:
SQL> SELECT * FROM V$VERSION;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for 64-bit Windows: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL> SHOW PARAMETER OPT
NAME TYPE VALUE
filesystemio_options string
object_cache_optimal_size integer 102400
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 10.2.0.4
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
plsql_optimize_level integer 2The OUTER JOIN produced the following results:
SQL> select e.id, e.name, l.id, l.leave_date
2 from emp e, leave l
3 where e.id = l.emp_id (+) ;
10000 rows selected.
Execution Plan
Plan hash value: 98076489
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 10000 | 380K| 9 (12)| 00:00:01 |
|* 1 | HASH JOIN RIGHT OUTER| | 10000 | 380K| 9 (12)| 00:00:01 |
| 2 | TABLE ACCESS FULL | LEAVE | 5017 | 80272 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL | EMP | 10000 | 224K| 5 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - access("E"."ID"="L"."EMP_ID"(+))
Statistics
0 recursive calls
0 db block gets
723 consistent gets
0 physical reads
0 redo size
364047 bytes sent via SQL*Net to client
7672 bytes received via SQL*Net from client
668 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
10000 rows processedThe inline subquery produced these results:
SQL> select e.id, e.name,
2 (select l.id from leave l where l.emp_id = e.id ) leave_id,
3 (select l.leave_date from leave l where l.emp_id = e.id ) leave_dat
4 from emp e ;
10000 rows selected.
Execution Plan
Plan hash value: 1706216391
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 10000 | 224K| 5 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| LEAVE | 1 | 9 | 3 (0)| 00:00:01 |
|* 2 | TABLE ACCESS FULL| LEAVE | 1 | 13 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| EMP | 10000 | 224K| 5 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("L"."EMP_ID"=:B1)
2 - filter("L"."EMP_ID"=:B1)
Statistics
0 recursive calls
0 db block gets
360705 consistent gets
0 physical reads
0 redo size
364053 bytes sent via SQL*Net to client
7672 bytes received via SQL*Net from client
668 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
10000 rows processedSee the 723 consistent gets versus 360705? That is a huge difference.
The second method may be more viable if you create indexes on the columns in the leave table that you are joining to your EMP table.
For example:
SQL> CREATE INDEX LEAD_ID_IDX ON LEAVE(EMP_ID, ID, LEAVE_DATE);
Index created.
SQL> set autotrace traceonly
SQL> select e.id, e.name,
2 (select l.id from leave l where l.emp_id = e.id ) leave_id,
3 (select l.leave_date from leave l where l.emp_id = e.id ) leave_date
4 from emp e ;
10000 rows selected.
Execution Plan
Plan hash value: 1822800249
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 10000 | 224K| 5 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN | LEAD_ID_IDX | 1 | 9 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | LEAD_ID_IDX | 1 | 13 | 2 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| EMP | 10000 | 224K| 5 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - access("L"."EMP_ID"=:B1)
2 - access("L"."EMP_ID"=:B1)
Statistics
1 recursive calls
0 db block gets
22111 consistent gets
19 physical reads
0 redo size
364053 bytes sent via SQL*Net to client
7672 bytes received via SQL*Net from client
668 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
10000 rows processedThe query improved by a more than a factor of 10 with the index but the consistent gets are still significantly higher then the OUTER JOIN query. Additionally I always try and take the approach when developing queries to minimize the number of table accesses possible. In your second place you have to access the LEAVE table twice, instead of once in the first query.
Maybe you are looking for
-
CHANGEOVER FROM TAXINJ TO TAXINN
HI all, TAXINJ and TAXINN cannot co exist in the same system. If you are talking about technical Upgrade, then I don't think this would be feasible since old Txn would have got posted with TAXINJ procedure with rates as defined in Tax codes and now a
-
Please help, I haven't been able to figure this one out on my own. I downloaded Maverick, and updated Mac Pages. Now g-mail won't let me send a message with a pages attachment. I get the message 'sending the message content to the server failed'. I
-
Price difference account in MIRO
Dear All, There is a Price Diff account hitting in MIRO...Wen i went to the PO and MIGO price it is the same difference which is reflecting in MIRO..PO is account assigned as cost centre. In po condition type maintained are BED-8%, Ecess-2%, Hsecess-
-
Hi chaps. Just got an N82 and though I'm loathe to ask for advice, I am truly stumped on this. I filmed a really cool video last night on the phone, but when I go to transfer it from my phone to PC via USB, it - and none of my photos - are showing up
-
Wrong Accounting Packet Counter !
Hi, In our DSL Service provider, We use Cisco Routers as a BRAS for years. recently I have noticed about an strength problem with accounting packets That I'm recieving from BRAS! right now our AAA configuration for PPPOE is something like this: 1- wh