Reg: query plan -

Hi Experts,
I was playing/experimenting with query plans but got stuck up with the below. I guess, I'm overlooking something.
ranit@XE11GR2>> create table t
  2  as
  3  select * from all_objects;
Table created.
ranit@XE11GR2>> exec dbms_stats.gather_table_stats('rb1','t');
PL/SQL procedure successfully completed.
ranit@XE11GR2>> create index t_uidx
  2  on
  3  t(owner, object_type, object_name);
Index created.
ranit@XE11GR2>> select * from t
  2  where owner = 'SYS';
Elapsed: 00:00:00.00
Execution Plan
Plan hash value: 1601196873
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT  |      |  1642 |   144K|    67   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T    |  1642 |   144K|    67   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   1 - filter("OWNER"='SYS')
ranit@XE11GR2>> select count(*) from t
  2  where owner = 'SYS';
Elapsed: 00:00:00.00
Execution Plan
Plan hash value: 1979783846
| Id  | Operation         | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT  |        |     1 |     7 |    11   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE   |        |     1 |     7 |            |          |
|*  2 |   INDEX RANGE SCAN| T_UIDX |  1642 | 11494 |    11   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   2 - access("OWNER"='SYS')
Doubt: Why does the first query have a FTS while the second query (with COUNT(*)) does an Index scan?
ranit@XE11GR2>> select owner, object_name, namespace from t
  2  where owner = 'SYS';
Elapsed: 00:00:00.05
Execution Plan
Plan hash value: 1601196873
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT  |      |  1642 | 47618 |    67   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T    |  1642 | 47618 |    67   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   1 - filter("OWNER"='SYS')
Also, in the above I'm seeing that if I add a non-indexed column in SELECT clause (like column 'namespace') it goes for a FTS. How does column in SELECT clause affect the use of Indexes?
Any pointers if highly appreciated.
Thanks,
Ranit

The second query doesn't have to visit the table - all the required data is in the index- and Oracle thinks that a range scan will only have to go through a small number of leaf blocks to find all the SYS entries.  The first query needs data which can only be found in the table, and Oracle thinks the 1642 rows it need to find will be spread across so many blocks that it's quicker to do the tablescan than jump to each one separately after doing an index range scan.
If you want to see how much work Oracle thinks it would take to use an indexed access path into the table, you could test by adding a hint to the query.
Regards
Jonathan Lewis
Now on twitter: @jloracle

Similar Messages

  • Query plan and negative value in where

    I have a question about this query:
    select g.col1,
    g.col2
    from tab1 g,
    tab2 part
    where part.col3 <> 0
    and g.col4 = 'PRO3'
    and g.col2 = part.col5
    and g.cod7 = -1
    This is the execution plan:
    SELECT STATEMENT, GOAL = ALL_ROWS               
    HASH JOIN               
    INDEX FAST FULL SCAN     SYS_C00254422     14     22453     516419
    TABLE ACCESS FULL     TAB2     920     67458     1079328
    If I change the select in this way:
    select g.col1,
    g.col2
    from tab1 g,
    tab2 part
    where part.col3 <> 0
    and g.col4 = 'PRO3'
    and g.col2 = part.col5
    and -g.cod7 = 1
    I have a new query plan:
    SELECT STATEMENT, GOAL = ALL_ROWS               
    NESTED LOOPS               
    INDEX FAST FULL SCAN     SYS_C00254422     
    TABLE ACCESS BY INDEX ROWID          TAB2     
    INDEX UNIQUE SCAN          SYS_C00254336     
    Oralce use a nested loop and the index of the table TAB1 and doesn't do the hash join.
    Why?
    I use oracle 10g
    Message was edited by:
    user613483
    Message was edited by:
    user613483

    SQL> desc TAB1
    Name Null? Type
    COL1 NOT NULL VARCHAR2(5)
    COL4 NOT NULL VARCHAR2(5)
    COL2 NOT NULL VARCHAR2(15)
    COL7 NOT NULL NUMBER(3)
    DTCOL8 NOT NULL DATE
    DRcol9 DATE
    LEVcol10 NUMBER(3)
    COL11 VARCHAR2(30)
    COD12 VARCHAR2(15)
    LEV13 NUMBER(3)
    COD14 VARCHAR2(15)
    LEV15 NUMBER(3)
    COD16 VARCHAR2(15)
    LEVN17 NUMBER(3)
    COD18 VARCHAR2(15)
    LEV19 NUMBER(3)
    CODNOD20 VARCHAR2(15)
    LEVNO21 NUMBER(3)
    CODNOD22 VARCHAR2(15)
    LEVN23 NUMBER(3)
    COD24 VARCHAR2(15)
    LEV25 NUMBER(3)
    CODNOD26 VARCHAR2(15)
    L27 NUMBER(3)
    CODN28 VARCHAR2(15)
    LEV28 NUMBER(3)
    D30 DATE
    SQL> desc tab2
    Name Null? Type
    COL5 NOT NULL VARCHAR2(15)
    DESY1 VARCHAR2(60)
    DESPA VARCHAR2(60)
    CODS VARCHAR2(5)
    CODNI VARCHAR2(5)
    CODZO VARCHAR2(10)
    CODC VARCHAR2(5)
    CDFIS VARCHAR2(30)
    CO VARCHAR2(30)
    CODVATI VARCHAR2(30)
    COT1 VARCHAR2(15)
    COT2 VARCHAR2(15)
    DCAT3 VARCHAR2(15)
    CAT4 VARCHAR2(15)
    COD VARCHAR2(15)
    COU VARCHAR2(5)
    FLG NOT NULL NUMBER(1)
    COT VARCHAR2(20)
    FLGCUSTD NOT NULL NUMBER(1)
    CODMOE VARCHAR2(5)
    FLG NOT NULL NUMBER(1)
    FLGC NOT NULL NUMBER(1)
    CODMOP VARCHAR2(5)
    CODC VARCHAR2(15)
    COELIV VARCHAR2(15)
    CONC VARCHAR2(15)
    COGMT VARCHAR2(10)
    COR VARCHAR2(5)
    COOUP VARCHAR2(15)
    VALDIT NUMBER(14,2)
    DTREDIT DATE
    DTRE DATE
    DTD DATE
    DST DATE
    DK DATE
    COCK VARCHAR2(5)
    CMOD VARCHAR2(5)
    FNN NOT NULL NUMBER(1)
    PGDCL VARCHAR2(60)
    PDB VARCHAR2(60)
    CXTEL VARCHAR2(15)
    ILCK VARCHAR2(15)
    DTTART DATE
    PVERY NUMBER(9)
    FLTUAL NOT NULL NUMBER(1)
    DVER DATE
    RIFE_INTERNO VARCHAR2(15)
    DATADATE
    ESENZIONE DATE
    NMSENZIONE VARCHAR2(15)
    VSED NUMBER(14,2)
    EORD NOT NULL NUMBER(1)
    EM VARCHAR2(30)
    COTER VARCHAR2(15)
    COUST VARCHAR2(15)
    CORINT VARCHAR2(15)
    TURFACE NUMBER(6)
    ODSURFACE NUMBER(6)
    ALINDEXPOT NUMBER(6)
    SSE NUMBER(6)
    NUSEATTR NUMBER(6)
    NUETTI NUMBER(6)
    CORTY VARCHAR2(15)
    DESEC VARCHAR2(60)
    QTEARI NUMBER(6)
    TOFACE NUMBER(6)
    COD VARCHAR2(30)
    FLGCI NUMBER(1)
    FLGC NUMBER(1)
    COL3 NUMBER(1)
    FLGCOL33 NUMBER(1)
    Query plan of the original select:
    1     SQL_ID 51kgr2x36h3y4, child number 0
    2     -------------------------------------
    3     select g.col1, g.col2 from tab1 g, tab2 part
    4     where part.col3 <> 0 and g.col4 = 'PRO3' and g.col2 =
    5     part.col5 and g.col7 = -1
    6     
    7     Plan hash value: 2145701647
    8     
    9     ---------------------------------------------------------------------------------------
    10     | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    11     ---------------------------------------------------------------------------------------
    12     | 0 | SELECT STATEMENT | | | | 938 (100)| |
    13     |* 1 | HASH JOIN | | 22485 | 856K| 938 (17)| 00:00:05 |
    14     |* 2 | INDEX FAST FULL SCAN| SYS_C00254422 | 22453 | 504K| 14 (8)| 00:00:01 |
    15     |* 3 | TABLE ACCESS FULL | TAB2 | 67458 | 1054K| 920 (16)| 00:00:05 |
    16     ---------------------------------------------------------------------------------------
    17     
    18     Predicate Information (identified by operation id):
    19     ---------------------------------------------------
    20     
    21     1 - access("G"."COL2"="PART"."COL5")
    22     2 - filter(("G"."COL7"=(-1) AND "G"."COL4"='PRO3'))
    23     3 - filter("PART"."COL3"<>0)
    24     
    Sql plan of the second quesry:
    1     SQL_ID g1hc2xj88sc7x, child number 0
    2     -------------------------------------
    3     select g.col1, g.col2 from tab1 g, tab2 part where
    4     part.col3 <> 0 and g.col4 = 'PRO3' and g.col2 = part.col5
    5     and -g.col7 = 1
    6     
    7     Plan hash value: 601419963
    8     
    9     ----------------------------------------------------------------------------------------------
    10     | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    11     ----------------------------------------------------------------------------------------------
    12     | 0 | SELECT STATEMENT | | | | 512 (100)| |
    13     | 1 | NESTED LOOPS | | 249 | 9711 | 512 (1)| 00:00:03 |
    14     |* 2 | INDEX FAST FULL SCAN | SYS_C00254422 | 248 | 5704 | 15 (14)| 00:00:01 |
    15     |* 3 | TABLE ACCESS BY INDEX ROWID| TAB2 | 1 | 16 | 2 (0)| 00:00:01 |
    16     |* 4 | INDEX UNIQUE SCAN | SYS_C00254336 | 1 | | 1 (0)| 00:00:01 |
    17     ----------------------------------------------------------------------------------------------
    18     
    19     Predicate Information (identified by operation id):
    20     ---------------------------------------------------
    21     
    22     2 - filter(((-"G"."COL7")=1 AND "G"."COL4"='PRO3'))
    23     3 - filter("PART"."COL3"<>0)
    24     4 - access("G"."COL2"="PART"."COL5")
    25     
    Index used:
    Primary key on tab2 SYS_C00254336:
    alter table TAB2
    add primary key (COL5)
    using index
    tablespace name_tablespace;
    Primary key on tab1 SYS_C00254422;
    alter table TAB1
    add primary key (COL1, COL4, COL2, COL7, DTCOL8 )
    using index
    tablespace name_tablespace;
    Message was edited by:
    user613483
    Message was edited by:
    user613483

  • SQL 2012 SP1 - How to determine a query that causes Error 8623 in SQL Log: The query processor ran out of internal resources and could not produce a query plan. This is a rare event...

    We are getting multiple 8623 Errors in SQL Log while running Vendor's software.
    How can you catch which Query causes the error?
    I tried to catch it using SQL Profiler Trace but it doesn't show which Query/Sp is the one causing an error. 
    I also tried to use Extended Event session to catch it, but it doesn't create any output either.
    Error:
    The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that
    reference a very large number of tables or partitions. Please simplify the query. If you believe you have received this message in error, contact Customer Support Services for more information.
    Extended Event Session that I used;
    CREATE EVENT SESSION
        overly_complex_queries
    ON SERVER
    ADD EVENT sqlserver.error_reported
        ACTION (sqlserver.sql_text, sqlserver.tsql_stack, sqlserver.database_id, sqlserver.username)
        WHERE ([severity] = 16
    AND [error_number] = 8623)
    ADD TARGET package0.asynchronous_file_target
    (SET filename = 'E:\SQLServer2012\MSSQL11.MSSQLSERVER\MSSQL\Log\XE\overly_complex_queries.xel' ,
        metadatafile = 'E:\SQLServer2012\MSSQL11.MSSQLSERVER\MSSQL\Log\XE\overly_complex_queries.xem',
        max_file_size = 10,
        max_rollover_files = 5)
    WITH (MAX_DISPATCH_LATENCY = 5SECONDS)
    GO
    -- Start the session
    ALTER EVENT SESSION overly_complex_queries
        ON SERVER STATE = START
    GO
    It creates only .xel file, but not .xem
    Any help/advice is greatly appreciated

    Hi VK_DBA,
    According to your error message, about which query statement may fail with error message 8623, as other post, you can use trace flag 4102 & 4118 for overcoming this error. Another way is looking for queries with very long IN lists, a large number of
    UNIONs, or a large number of nested sub-queries. These are the most common causes of this particular error message.
    The error 8623 occurs when attempting to select records through a query with a large number of entries in the "IN" clause (> 10,000). For avoiding this error, I suggest that you could apply the latest Cumulative Updates media for SQL Server 2012 Service
    Pack 1, then simplify the query. You may try divide and conquer approach to get part of the query working (as temp table) and then add extra joins / conditions. Or You could try to run the query using the hint option (force order), option (hash join), option
    (merge join) with a plan guide.
    For more information about error 8623, you can review the following article.
    http://blogs.technet.com/b/mdegre/archive/2012/03/13/8623-the-query-processor-ran-out-of-internal-resources-and-could-not-produce-a-query-plan.aspx
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • How to setup a query plan in effective at any time for SP or SQL query?

    I have a SP which include a group by SQL statement. It retrieve data from a couple of tables which are over 1G size,
    When I run this SP at first time, it take more than 5 minutes to get the result. then I run it again and again, Finally, it become very quick, I can get the result within second.
    Not sure why. I guess it is because of query plan.
    How to make it running at first time to get result within second? How to force a better best query plan in effective at first time to run the query?
    If the engine has better plan in memory, could it be lost at some point? because I have the complain from end user said some times it is fast, sometime it is very slow.
    How to resolve this problem?

    thanks, kevin. Here is the pesudo query( I modify table name as business rule from my company). you are right, mytab3 is a lookup table.
    Select d.stock,i.description,c.categoryname,
    Round(IsNull(Sum(d.qty),0),2) AS qty,
    From mytab1 d,mytab2 s,invent i,mytab3 c       
    Where
    d.stock != 'param1'
    And d.id1 = s.id1    --id1: univarchar(11)        
    And i.code = c.code   --code:univarchar(2)         
    And d.stock = i.stock  --stock: univarchar(12)           
    And i.code2 = d.code2  --code2: univarchar(2)
    And d.code2 = 'param2'
    And s.id2 = 'param3'   --id2: univarchar(6)
    Group By  c.categoryname,d.stock,i.description
    Order By d.stock
    here is the query plan when run this query:
    The command completed with no results returned
    QUERY PLAN FOR STATEMENT 1 (at line 1).
    Executed in parallel by coordinating process and 4 worker processes.
        STEP 1
            The type of query is SELECT (into Worktable1).
            GROUP BY
            Evaluate Grouped SUM OR AVERAGE AGGREGATE.
            Evaluate Grouped SUM OR AVERAGE AGGREGATE.
            Evaluate Grouped SUM OR AVERAGE AGGREGATE.
            Executed in parallel by coordinating process and 4 worker processes.
            FROM TABLE
                mytab2
                s
            Nested iteration.
            Index : ind_mytab2 _id2
            Forward scan.
            Positioning by key.
            Keys are:
                id2  ASC
            Executed in parallel with a 4-way hash scan.
            Using I/O Size 16 Kbytes for index leaf pages.
            With LRU Buffer Replacement Strategy for index leaf pages.
            Using I/O Size 16 Kbytes for data pages.
            With LRU Buffer Replacement Strategy for data pages.
            FROM TABLE
                mytab1
                d
            Nested iteration.
            Index : ind_det_inv
            Forward scan.
            Positioning by key.
            Keys are:
                id1  ASC
            Using I/O Size 16 Kbytes for index leaf pages.
            With LRU Buffer Replacement Strategy for index leaf pages.
            Using I/O Size 16 Kbytes for data pages.
            With LRU Buffer Replacement Strategy for data pages.
            FROM TABLE
                invent
                i
            Nested iteration.
            Using Clustered Index.
            Index : invent_pk
            Forward scan.
            Positioning by key.
            Keys are:
                stock  ASC
                code2  ASC
            Using I/O Size 2 Kbytes for data pages.
            With LRU Buffer Replacement Strategy for data pages.
            FROM TABLE
                mytab3
                c
            Nested iteration.
            Table Scan.
            Forward scan.
            Positioning at start of table.
            Using I/O Size 2 Kbytes for data pages.
            With LRU Buffer Replacement Strategy for data pages.
            TO TABLE
                Worktable1.
            Parallel work table merge.
        STEP 2
            The type of query is INSERT.
            The update mode is direct.
            Executed by coordinating process.
            Worktable2 created, in allpages locking mode, for ORDER BY.
            FROM TABLE
                Worktable1.
            Nested iteration.
            Table Scan.
            Forward scan.
            Positioning at start of table.
            Using I/O Size 8 Kbytes for data pages.
            With MRU Buffer Replacement Strategy for data pages.
            TO TABLE
                Worktable2.
        STEP 3
            The type of query is SELECT.
            Executed by coordinating process.
            This step involves sorting.
            FROM TABLE
                Worktable2.
            Using GETSORTED
            Table Scan.
            Forward scan.
            Positioning at start of table.
            Using I/O Size 8 Kbytes for data pages.
            With MRU Buffer Replacement Strategy for data pages.
    Total estimated I/O cost for statement 1 (at line 1): 1409882.
    The sort for Worktable2 is done in Serial

  • Can users see the query plan of a SQL query in Oracle?

    Hi,
    I wonder for a given sql query, after the system optimization, can I see the query plan in oracle? If yes, how to do that? thank you.
    Xing

    You can use explain plan in SQLPlus
    SQL>  explain plan for select * from user_tables;
    Explained.
    Elapsed: 00:00:01.63
    SQL> select * from table(dbms_xplan.display());
    PLAN_TABLE_OUTPUT
    Plan hash value: 806004009
    | Id  | Operation                       | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                |          |  2014 |  1123K|   507   (6)| 00:00:07 |
    |*  1 |  HASH JOIN RIGHT OUTER          |          |  2014 |  1123K|   507   (6)| 00:00:07 |
    |   2 |   TABLE ACCESS FULL             | SEG$     |  4809 |   206K|    34   (3)| 00:00:01 |
    |*  3 |   HASH JOIN RIGHT OUTER         |          |  1697 |   873K|   472   (6)| 00:00:06 |
    |   4 |    TABLE ACCESS FULL            | USER$    |    74 |  1036 |     3   (0)| 00:00:01 |
    |*  5 |    HASH JOIN OUTER              |          |  1697 |   850K|   468   (6)| 00:00:06 |
    |   6 |     NESTED LOOPS OUTER          |          |  1697 |   836K|   315   (6)| 00:00:04 |
    |*  7 |      HASH JOIN                  |          |  1697 |   787K|   226   (8)| 00:00:03 |
    |   8 |       TABLE ACCESS FULL         | TS$      |    13 |   221 |     5   (0)| 00:00:01 |
    |   9 |       NESTED LOOPS              |          |  1697 |   759K|   221   (8)| 00:00:03 |
    |  10 |        MERGE JOIN CARTESIAN     |          |  1697 |   599K|   162  (10)| 00:00:02 |
    |* 11 |         HASH JOIN               |          |     1 |   326 |     1 (100)| 00:00:01 |
    |* 12 |          FIXED TABLE FULL       | X$KSPPI  |     1 |    55 |     0   (0)| 00:00:01 |
    |  13 |          FIXED TABLE FULL       | X$KSPPCV |   100 | 27100 |     0   (0)| 00:00:01 |
    |  14 |         BUFFER SORT             |          |  1697 | 61092 |   162  (10)| 00:00:02 |
    |* 15 |          TABLE ACCESS FULL      | OBJ$     |  1697 | 61092 |   161  (10)| 00:00:02 |
    |* 16 |        TABLE ACCESS CLUSTER     | TAB$     |     1 |    96 |     1   (0)| 00:00:01 |
    |* 17 |         INDEX UNIQUE SCAN       | I_OBJ#   |     1 |       |     0   (0)| 00:00:01 |
    |  18 |      TABLE ACCESS BY INDEX ROWID| OBJ$     |     1 |    30 |     1   (0)| 00:00:01 |
    |* 19 |       INDEX UNIQUE SCAN         | I_OBJ1   |     1 |       |     0   (0)| 00:00:01 |
    |  20 |     TABLE ACCESS FULL           | OBJ$     | 52728 |   411K|   151   (4)| 00:00:02 |
    Predicate Information (identified by operation id):
       1 - access("T"."FILE#"="S"."FILE#"(+) AND "T"."BLOCK#"="S"."BLOCK#"(+) AND
                  "T"."TS#"="S"."TS#"(+))
       3 - access("CX"."OWNER#"="CU"."USER#"(+))
       5 - access("T"."DATAOBJ#"="CX"."OBJ#"(+))
       7 - access("T"."TS#"="TS"."TS#")
      11 - access("KSPPI"."INDX"="KSPPCV"."INDX")
      12 - filter("KSPPI"."KSPPINM"='_dml_monitoring_enabled')
      15 - filter("O"."OWNER#"=USERENV('SCHEMAID') AND BITAND("O"."FLAGS",128)=0)
      16 - filter(BITAND("T"."PROPERTY",1)=0)
      17 - access("O"."OBJ#"="T"."OBJ#")
      19 - access("T"."BOBJ#"="CO"."OBJ#"(+))
    42 rows selected.
    Elapsed: 00:00:03.61
    SQL> If your plan table does not exist, execute the script $ORACLE_HOME/RDBMS/ADMIN/utlxplan.sql to create the table.

  • What is the best way to query planned orders or work orders for make items and identify the buy component that is short for supply and vice versa?

    What is the best way to query planned orders or work orders for make items and identify the buy component that is short for supply and vice versa?

    What is the best way to query planned orders or work orders for make items and identify the buy component that is short for supply and vice versa?

  • SQL Server Query Plan Generation take longer

    Dear all,
    We are dealing with a wired issue where queries on there first execution take approx 1 min to 2 mins to execute and later execution completes in less than a second,Can you please help us understand why sql server is taking longer time to generated the query
    plan
    Below is the result of files stats
    Mohd Sufian www.sqlship.wordpress.com Please mark the post as Answered if it helped.

    SYS.DM_OS_MEMORY_CLERKS
    MEMORYCLERK_SQLOPTIMIZER 136 912
    CACHESTORE_PHDR 1864 0
    CACHESTORE_XMLDBTYPE 8 0
    CACHESTORE_EVENTS 16 0
    USERSTORE_OBJPERM 824 0
    USERSTORE_TOKENPERM 840 968
    MEMORYCLERK_SQLSTORENG 2736 4312
    CACHESTORE_FULLTEXTSTOPLIST 32 0
    MEMORYCLERK_XE 64 168
    CACHESTORE_XPROC 72 0
    OBJECTSTORE_SNI_PACKET 3336 112
    CACHESTORE_BROKERRSB 8 0
    OBJECTSTORE_SERVICE_BROKER 424 0
    MEMORYCLERK_SQLSERVICEBROKERTRANSPORT 48 0
    MEMORYCLERK_XE_BUFFER 0 0
    MEMORYCLERK_SQLGENERAL 1608 4144
    CACHESTORE_XMLDBATTRIBUTE 8 0
    MEMORYCLERK_SQLHTTP 8 0
    CACHESTORE_STACKFRAMES 0 16
    MEMORYCLERK_SQLCONNECTIONPOOL 2440 0
    MEMORYCLERK_SQLSERVICEBROKER 152 544
    CACHESTORE_NOTIF 16 0
    CACHESTORE_XMLDBELEMENT 8 0
    OBJECTSTORE_LOCK_MANAGER 24 0
    MEMORYCLERK_SQLBUFFERPOOL 0 1688
    MEMORYCLERK_SQLSOAP 0 0
    MEMORYCLERK_TRACE_EVTNOTIF 0 0
    CACHESTORE_OBJCP 6576 512
    CACHESTORE_CONVPRI 64 0
    MEMORYCLERK_QSRANGEPREFETCH 0 0
    CACHESTORE_BROKERREADONLY 80 0
    MEMORYCLERK_SQLCLRASSEMBLY 0 0
    MEMORYCLERK_SOSNODE 8 16320
    MEMORYCLERK_SQLQUERYPLAN 0 0
    OBJECTSTORE_SECAUDIT_EVENT_BUFFER 16 0
    MEMORYCLERK_BHF 0 0
    CACHESTORE_SQLCP 22680 3544
    OBJECTSTORE_LBSS 96 192
    CACHESTORE_SYSTEMROWSET 1832 0
    MEMORYCLERK_FULLTEXT 24 0
    USERSTORE_SCHEMAMGR 2632 328
    MEMORYCLERK_SQLQUERYCOMPILE 0 0
    CACHESTORE_TEMPTABLES 16 0
    CACHESTORE_BROKERTBLACS 200 0
    CACHESTORE_BROKERTO 8 0
    CACHESTORE_BROKERKEK 8 0
    MEMORYCLERK_SQLXML 0 0
    USERSTORE_SXC 64 0
    MEMORYCLERK_SNI 240 32
    MEMORYCLERK_FULLTEXT_SHMEM 0 0
    CACHESTORE_BROKERUSERCERTLOOKUP 8 0
    CACHESTORE_BROKERDSH 8 0
    MEMORYCLERK_SQLSOAPSESSIONSTORE 0 0
    MEMORYCLERK_SQLQERESERVATIONS 0 0
    MEMORYCLERK_HOST 16 0
    MEMORYCLERK_SQLCLR 8 0
    MEMORYCLERK_SQLXP 16 0
    USERSTORE_DBMETADATA 1912 0
    MEMORYCLERK_SQLUTILITIES 112 0
    CACHESTORE_VIEWDEFINITIONS 16 0
    MEMORYCLERK_SQLQUERYEXEC 80 0
    sys.dm_os_performance_counters
    object_name counter_name cntr_value
    SQLServer:Buffer Manager Buffer cache hit ratio 556
    SQLServer:Buffer Manager Buffer cache hit ratio base 612
    SQLServer:Buffer Manager Page lookups/sec 4054066
    SQLServer:Buffer Manager Free list stalls/sec 0
    SQLServer:Buffer Manager Free pages 483
    SQLServer:Buffer Manager Total pages 503088
    SQLServer:Buffer Manager Target pages 1710080
    SQLServer:Buffer Manager Database pages 494479
    SQLServer:Buffer Manager Reserved pages 0
    SQLServer:Buffer Manager Stolen pages 8126
    SQLServer:Buffer Manager Lazy writes/sec 0
    SQLServer:Buffer Manager Readahead pages/sec 378700
    SQLServer:Buffer Manager Page reads/sec 493985
    SQLServer:Buffer Manager Page writes/sec 2421
    SQLServer:Buffer Manager Checkpoint pages/sec 0
    SQLServer:Buffer Manager AWE lookup maps/sec 0
    SQLServer:Buffer Manager AWE stolen maps/sec 0
    SQLServer:Buffer Manager AWE write maps/sec 0
    SQLServer:Buffer Manager AWE unmap calls/sec 0
    SQLServer:Buffer Manager AWE unmap pages/sec 0
    SQLServer:Buffer Manager Page life expectancy 262
    SQLServer:Cursor Manager by Type Cache Hit Ratio 0
    SQLServer:Cursor Manager by Type Cache Hit Ratio Base 0
    SQLServer:Cursor Manager by Type Cached Cursor Counts 0
    SQLServer:Cursor Manager by Type Cursor Cache Use Counts/sec 0
    SQLServer:Cursor Manager by Type Cursor Requests/sec 0
    SQLServer:Cursor Manager by Type Active cursors 0
    SQLServer:Cursor Manager by Type Cursor memory usage 0
    SQLServer:Cursor Manager by Type Cursor worktable usage 0
    SQLServer:Cursor Manager by Type Number of active cursor plans 0
    SQLServer:Cursor Manager by Type Cache Hit Ratio 0
    SQLServer:Cursor Manager by Type Cache Hit Ratio Base 0
    SQLServer:Cursor Manager by Type Cached Cursor Counts 0
    SQLServer:Cursor Manager by Type Cursor Cache Use Counts/sec 0
    SQLServer:Cursor Manager by Type Cursor Requests/sec 0
    SQLServer:Cursor Manager by Type Active cursors 0
    SQLServer:Cursor Manager by Type Cursor memory usage 0
    SQLServer:Cursor Manager by Type Cursor worktable usage 0
    SQLServer:Cursor Manager by Type Number of active cursor plans 0
    SQLServer:Cursor Manager by Type Cache Hit Ratio 0
    SQLServer:Cursor Manager by Type Cache Hit Ratio Base 0
    SQLServer:Cursor Manager by Type Cached Cursor Counts 0
    SQLServer:Cursor Manager by Type Cursor Cache Use Counts/sec 0
    SQLServer:Cursor Manager by Type Cursor Requests/sec 0
    SQLServer:Cursor Manager by Type Active cursors 0
    SQLServer:Cursor Manager by Type Cursor memory usage 0
    SQLServer:Cursor Manager by Type Cursor worktable usage 0
    SQLServer:Cursor Manager by Type Number of active cursor plans 0
    SQLServer:Cursor Manager by Type Cache Hit Ratio 0
    SQLServer:Cursor Manager by Type Cache Hit Ratio Base 0
    SQLServer:Cursor Manager by Type Cached Cursor Counts 0
    SQLServer:Cursor Manager by Type Cursor Cache Use Counts/sec 0
    SQLServer:Cursor Manager by Type Cursor Requests/sec 0
    SQLServer:Cursor Manager by Type Active cursors 0
    SQLServer:Cursor Manager by Type Cursor memory usage 0
    SQLServer:Cursor Manager by Type Cursor worktable usage 0
    SQLServer:Cursor Manager by Type Number of active cursor plans 0
    SQLServer:Cursor Manager Total Cursor conversion rate 0
    SQLServer:Cursor Manager Total Async population count 0
    SQLServer:Cursor Manager Total Cursor flushes 0
    SQLServer:Memory Manager Connection Memory (KB) 2864
    SQLServer:Memory Manager Granted Workspace Memory (KB) 0
    SQLServer:Memory Manager Lock Memory (KB) 7944
    SQLServer:Memory Manager Lock Blocks Allocated 40550
    SQLServer:Memory Manager Lock Owner Blocks Allocated 43550
    SQLServer:Memory Manager Lock Blocks 10003
    SQLServer:Memory Manager Lock Owner Blocks 10133
    SQLServer:Memory Manager Maximum Workspace Memory (KB) 10280520
    SQLServer:Memory Manager Memory Grants Outstanding 0
    SQLServer:Memory Manager Memory Grants Pending 0
    SQLServer:Memory Manager Optimizer Memory (KB) 1048
    SQLServer:Memory Manager SQL Cache Memory (KB) 2080
    SQLServer:Memory Manager Target Server Memory (KB) 13680640
    SQLServer:Memory Manager Total Server Memory (KB) 4024704
    Mohd Sufian www.sqlship.wordpress.com Please mark the post as Answered if it helped.

  • Query Plan 'group-by' clause

    In evaluating several query plans, I've discovered several sqlstop messages that read:
    <groupBy preclustered="true" sqlstop="Cannot generate SQL for the 'group-by' clause because it is not equivalent to the relational GROUP BY clause" stable="true">
    I've examined the XQuery code and find no group clause and I can't find a reference to this message in the documentation or by googling the text. I assume that the grouping is being done implicitly by ODSI since it is not in the XQuery source. I have tried restructuring the code to no avail.
    My question is -- is this causing me a performance problem since the sql is not generated, and if so, what steps must I take in the xquery structure to avoid this issue.
    Many thanks to anyone who can provide some insight into this.
    Regards,
    PB

    is this causing me a performance problem since the sql is not generatedMy question is - why are you asking this question? :) Do you have a performance problem? The "Best Practices" posted as an announcement in this forum might help. Otherwise engage customer support.
    To answer your question - your xquery likely generates nested/hierarchical xml - and looks something like below - which can be implemented with a sql left-outer-join ordered by CUSTOMER_ID of the customer-table, and taking the rows returned and ... grouping by CUSTOMER_ID to eliminate the duplicate customer information. So there's your group-by. But you cannot write sql that has a left-outer join, and then a group-by on the left-hand side. So the group by is done in the engine. Since the results are already sorted, the group-by in the engine simply skips over the duplicates (i.e. it's basically free).
    for $c in CUSTOMER()
    where $c/LAST_NAME = $lastname
    return
    <CUSTOMER>
    ... $c/CUSTOMER_ID ... (: in a left-outer-join, the CUSTOMER_ID is duplicated for every ORDER :)
    { for $o in ORDER()
    where $o/CUSTOMER_ID eq $c/CUSTOMER_ID
    return
    </CUSTOMER>

  • Reading the DAX query plan of a trace against a query on a Tabular model

    Hi,
    I'm monitoring a Tabular model queried by an Excel workbook. Inside SQL Profiler I've choosen as events the VertiPaq SE Query End, the Query End and the DAX Query Plan. But this last event isn't more readable.
    How can I read the info collected in the DAX Query Plan in a simple manner?
    Thanks

    It is fairly complex to read the DAX Query Plan. I don't think there are currently tools that make it easier to read. (Watch the DAX Studio project on codeplex as they may include tools for this in the future.) I would recommend you review the Tabular
    Performance Guide which has a good explanation of the DAX Query Plan:
    http://aka.ms/ASTabPerf2012
    http://artisconsulting.com/Blogs/GregGalloway

  • Select Query Hangs / No DB Locks / Query Plan is good

    I have below query in application which hangs ( Only sometimes ) and there are some session which also try to insert data into this tables also starts getting hanged.
    SELECT DISTINCT F2 || ' - ' || F3 || ' - ' || F4
    FROM Table1
    WHERE F4 = 6160
    AND F1|| F2|| F3 NOT IN (
    SELECT F2|| F3 || F4
    FROM Table2
    WHERE F1 = 181)
    F2 - varchar(4)
    F3- varchar(100)
    F4- varchar(20)
    F1,F1 are NUMBER
    Table1 has one unique index comprising all fields in ORDER F1,F2, X,F3, F4,Y - X,Y are some different field.
    Table2 has one unique index comprising all fields in ORDER F1,F3, F4,F2 are some different field.
    Below are facts from DBA ----
    1- Session Query Plan was excellent -
    2 - No tables were locked in DB
    3 - Statistics on this table Table1 was calculated on Feb, 2008 and shows 8 millions rows but actual current row count is 13 million. DBA says sometime analyzing statistics again may cause poor query performance.
    4- There were 8 session in DB, 1 was for above select statement and other 7 were trying to insert data into above table.
    Can you please advise what could else be verified to root cause issue as it has been hanging many times - hence causing other session to hang ?
    Many Thanks

    Can you clarify exactly what the DBA meant by "No tables were locked in DB"? What was the exact query that was used to determine this? Was it hitting V$LOCK (GV$LOCK in a RAC system)? Or the DBA_BLOCKERS and DBA_WAITERS tables? Or something else? The specific query here is important because there is a world of difference between a row-level lock and a table-level lock. Of course, locks would never prevent a SELECT statement from running, but it could cause problems for the INSERT statements.
    I strongly concur with Old DBA's suggestion about refactoring the query to not do the concatenation in the NOT IN clause.
    Are the F4 = 6160 and F1 = 181 conditions really using hard-coded numeric literals? Or are these bind variables? Is the data in F1 or F4 skewed-- that is, are there certain values that are more likely than other values?
    How many rows would you expect to be in Table1 with an F4 value of 6160? How many rows in Table2 with a F1 value of 181?
    Justin

  • Merge cartesian join in query plan

    Hi All
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    W are using many GTT's in our code, the query plan have Merge Cartesain join showing cardinality as '1' which is incorrect, as GTT tables have many rows. Due to this query is taking ages to execute.
    I am trying to sue dynamic sampling, but it doesn't seem to work.
    please help on this.

    user8650395 wrote:
    Hi All
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    W are using many GTT's in our code, the query plan have Merge Cartesain join showing cardinality as '1' which is incorrect, as GTT tables have many rows. Due to this query is taking ages to execute.
    I am trying to sue dynamic sampling, but it doesn't seem to work.
    please help on this.Interesting.
    There was a a thread a day or two ago about when dynamic sampling does not work. You can search OTN for it if you like. Also check the docs to make sure that dynamic sampling works with GTTS
    One problem with GTTS is getting accurate statistics. Have you considered using DBMS_STATISTICS to set the statistics on the table to adjust the cardinality?
    Your cardinality of 1 sounds incorrect. In theory a cartesian join against one row should be painelss; unfortunately your cardinality figure seems to be off! Sometimes in cases like yours the cost-based optimizer will choose a Cartesian join even when the table joins are properly specified.

  • Sql Query Plan with ROWNUM

    Oracle 10g:
    I have a table with index, when I run that query on that index it's fine. I get into problem if I add ROWNUM in that query, query slows down from 1 sec to 30 sec. I don't know why. for eg:
    select * from (select * from A where b = 1) where ROWNUM < 1000 becomes very slow:
    Query Plan for select * from A where b = 1 (Query is just an example):
    Rows     Plan     
    208912     SELECT STATEMENT      
    208912     SORT ORDER BY      
    208912     HASH JOIN RIGHT OUTER      
    408     INDEX FULL SCAN PK_BAD_ACK_TASK     
    208912     HASH JOIN RIGHT OUTER      
    16     INDEX FULL SCAN PK_INFORMATIONAL_TASK     
    208912     HASH JOIN RIGHT OUTER      
    1     INDEX FULL SCAN PK_SYSTEM_ERROR_TASK     
    208912     HASH JOIN RIGHT OUTER      
    1     INDEX FULL SCAN PK_REJECTED_TRANSMISSION     
    208912     HASH JOIN RIGHT OUTER      
    1     INDEX FULL SCAN PK_ONHOLD_TASK     
    208912     HASH JOIN RIGHT OUTER      
    329465     INDEX FAST FULL SCAN PK_FAILED_MESSAGE     
    208912     TABLE ACCESS FULL TASK     
    Query when I add ROWNUM (slow query as mentioned above):
    Rows     Plan     
    999     SELECT STATEMENT      
    <NULL>     COUNT STOPKEY      
    208912     VIEW      
    208912     SORT ORDER BY STOPKEY      
    208912     HASH JOIN RIGHT OUTER      
    408     INDEX FULL SCAN PK_BAD_ACK_TASK     
    208912     NESTED LOOPS OUTER      
    208912     NESTED LOOPS OUTER      
    208912     NESTED LOOPS OUTER      
    208912     HASH JOIN RIGHT OUTER      
    329465     INDEX FAST FULL SCAN PK_FAILED_MESSAGE     
    208912     HASH JOIN RIGHT OUTER      
    16     INDEX FULL SCAN PK_INFORMATIONAL_TASK     
    208912     TABLE ACCESS FULL TASK     
    1     INDEX FAST FULL SCAN PK_ONHOLD_TASK     
    1     INDEX FAST FULL SCAN PK_REJECTED_TRANSMISSION     
    1     INDEX FAST FULL SCAN PK_SYSTEM_ERROR_TASK

    user628400 wrote:
    Oracle 10g:
    I have a table with index, when I run that query on that index it's fine. I get into problem if I add ROWNUM in that query, query slows down from 1 sec to 30 sec. I don't know why. for eg:Some notes:
    * When using ROWNUM the cost based optimizer switches to a FIRST_ROWS_N mode, this might explain the significant difference in the execution plan
    * Try to get a more meaningful output using DBMS_XPLAN.DISPLAY
    * Since you're already on 10g, try to compare the actual cardinalities to the estimates using DBMS_XPLAN.DISPLAY_CURSOR with the "ALLSTATS LAST" option and the GATHER_PLAN_STATISTICS hint.
    See e.g. here for more information how to do it: http://jonathanlewis.wordpress.com/2006/11/09/dbms_xplan-in-10g/
    This way you should be able to tell where the optimizer assumptions go wrong so that it thinks that the second one is better than the first one
    A simple remedy you might want to try that should get you back to plan 1 is the following:
    select * from (
    select ROWNUM as rn, a.* from (select * from A where b = 1 ORDER BY<your_order_criteria>) a
    where rn < 1000;Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/
    Edited by: Randolf Geist on Jan 11, 2009 9:33 PM
    Added the obvious sort ORDER BY

  • Actual Query Plan not running

    I am using SQL Server 2012 (11.0.5058.0) and I am trying to learn Execution Plan Basics.  One of the tasks is to run the "Actual Query Plan" by CTRL+M.  When I try this nothing happens.  I can do the "Display Estimated
    Query Plan" and it works.  Why can't I do the Actual Query Plan?

    Hi,
    To display Actual Query Plan, you have to execute the query. CTRL+M merely toggles to display Actual Query Plan or not.
    See:
    Display an Actual Execution Plan
    Hope this helps,
    ~ J.

  • SQL 2005 v9.0.2047 (SP1) - The query processor could not produce a query plan

    Hi Everyone:
    *Before* I actually call up Microsoft SQL Customer Support Services and ask them, I wanted to ping other people to see if you have ever ran into this exact error
    "Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services."
    I would have searched the forums myself, but at this moment in time, search is broken :(
    If anyone has run into this error before, what conditions would exist that this could happen?  That is, if I can sniff this out with suggestions from the community, I would be happy to do so. 
    It is an oddity because if I alter a couple subqueries in the where clause [ i.e., where tab.Col = (select val from tab2 where id='122') ]to not have subqueries [hand coded values], then the t-sql result is fine.  It's not as if subqueries are oddities... I've used them when appropriate.
    fwiw - Not a newbie t-sql guy.  ISV working almost daily with t-sql since MS SQL 2000.  I have never seen this message before...at least I don't recall ever seeing it.
    Thanks in advance for other suggested examination paths.

    This code also produces the error... the text is from an incident a while ago that I reported to microsoft.
    --I just found a way to break the query engine. Looks like the SQL Server team missed something. I was generating phony data for test cases, by the way.
    --Bad code:
    DECLARE @t_Asset TABLE
    (Asset_Id INT)
    INSERT INTO @t_Asset (Asset_Id) VALUES (1)
    INSERT INTO @t_Asset (Asset_Id) VALUES (2)
    INSERT INTO @t_Asset (Asset_Id) VALUES (3)
    DECLARE @Record_id INT
    ,@File_id NVARCHAR(MAX)
    ,@SKP_Cust_id NVARCHAR(MAX)
    ,@Unique_Barcode NVARCHAR(MAX)
    SELECT @Record_Id = (SELECT TOP 1 Asset_Id FROM @t_Asset)
    , @file_id = (SELECT LEFT(REPLACE(CAST(NEWID() AS NVARCHAR(50)), '-', ''), 10))
    ,@Unique_Barcode=(SELECT LEFT(REPLACE(CAST(NEWID() AS NVARCHAR(50)), '-', ''), 15))
    go
    --Msg 8624, Level 16, State 116, Line 12
    --Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services.
    --Code that doesn’t fry the optimizing engine:
    DECLARE @t_Asset TABLE
    (Asset_Id INT)
    INSERT INTO @t_Asset (Asset_Id) VALUES (1)
    INSERT INTO @t_Asset (Asset_Id) VALUES (2)
    INSERT INTO @t_Asset (Asset_Id) VALUES (3)
    DECLARE @Record_id INT
    ,@File_id NVARCHAR(MAX)
    ,@SKP_Cust_id NVARCHAR(MAX)
    ,@Unique_Barcode NVARCHAR(MAX)
    SELECT @Record_Id = (SELECT TOP 1 Asset_Id FROM @t_Asset)
    SELECT @file_id = (SELECT LEFT(REPLACE(CAST(NEWID() AS NVARCHAR(50)), '-', ''), 10))
    SELECT @Unique_Barcode=(SELECT LEFT(REPLACE(CAST(NEWID() AS NVARCHAR(50)), '-', ''), 15))

  • Conversion away from column type may result in sub-optimal query plan

    Hello all,
    I have the following select statement in a cursor compiled in a package.
    SELECT id
    FROM table
    WHERE TRUNC(ts) >= TRUNC(SYSDATE - p_days)
    However I get 4 warnings that read:
    PLW-07204: conversion away from column type may result in sub-optimal query plan
    Does anyone know of a way to rewrite the query to avoid the compilation warnings?
    I'm just trying to compare the date without the time...
    Thanks in advance
    Dan

    For what it is worth, whenever you compare a date column to either sysdate or any built-in function returning a date you will get that warning.
    SQL> desc t
    Name                                      Null?    Type
    ID                                                 NUMBER
    DT                                                 DATE
    SQL> SELECT DUMP(dt), DUMP(trunc(dt)), dump(sysdate)
      2  FROM t;
    DUMP(DT)                            DUMP(TRUNC(DT))                  DUMP(SYSDATE)
    Typ=12 Len=7: 120,107,7,12,15,16,43 Typ=13 Len=8: 7,215,7,12,0,0,0,0 Typ=13 Len=8: 7,215,7,12,14,16,11,0But,
    SQL> CREATE FUNCTION f(p_v IN VARCHAR2) RETURN DATE AS
      2  BEGIN
      3     RETURN TO_DATE(p_v, 'dd-mon-yyyy');
      4  END;
      5  /
    Function created.
    SQL> SELECT DUMP(f('01-jan-2000')) FROM dual;
    DUMP(F('01-JAN-2000'))
    Typ=12 Len=7: 120,100,1,1,1,1,1John

Maybe you are looking for

  • Eclipse helios Metro runtime

    Hi, I am trying to get Metro runtime in eclipse helios, but without success. I have tried with oepe bundle and also with latest helios release and install glassfish tools bundle via Eclipse marketspace. Any clue? brg

  • Power cords for older hardware?

    Hi, Anyone know where I can get power cords for a PowerMac G3 (beige short desktop) and an Apple Multiple Scan 15 AV Display? Willing to pay a fair price! Thanks in advance, --Prahas

  • JInitiator for Dicoverer web-version on Win XP

    I am attempting to run Discoverer online through my web browser (Internet Explorer 6.0) but I keep getting the following error message. "JInitiator 1.3.1.13 is not installed properly" . Any ideas how to resolve this. and where can I get JInitiator fr

  • Quicktime Broadcaster H.264 Configuration

    Hey, Does anyone have any knowledge of how to configure H.264 settings in Quicktime Broadcaster? The specs on www.apple.com/quicktime/broadcaster/specs.html say it supports both H.264 Baseline profile and H.264 Main profile, but the software only giv

  • Requisite JRE not found while installing CRM mobile client

    Hi Experts, We have been installing SAP CRM Mobile client component and when we start installation it stops showing the message "Requisite version of JRE not found". We are having java version j2sdk1.4.2_12 in the server and as per the installation g