Home » SQL & PL/SQL » SQL & PL/SQL » Query execution changes in oracle 11.2.0.4.5 version (oracle 11.2.0.4.5)
Query execution changes in oracle 11.2.0.4.5 version [message #634750] Sun, 15 March 2015 00:57 Go to next message
avineshr
Messages: 14
Registered: September 2012
Location: malaysia
Junior Member
Hi All ,

Please let us know after upgrade of oracle to 11.2.0.4.5 version.

A query in below format is not working as expected.

T1 is table which has no data.
create table T1
(
  table_name      VARCHAR2(30),
  tablespace_name VARCHAR2(30)
)


Let us know why below query is not returning records in version 11.2.0.4.5 in previous version it is working fine.
 
SELECT 1  FROM (SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM dual) WHERE col1-col2>0
Re: Query execution changes in oracle 11.2.0.4.5 version [message #634751 is a reply to message #634750] Sun, 15 March 2015 01:10 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Go to MOS and raise a SR to Oracle.

Re: Query execution changes in oracle 11.2.0.4.5 version [message #634752 is a reply to message #634751] Sun, 15 March 2015 01:14 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Post your OS version.
Post the execution plan for the query:
EXPLAIN PLAN FOR <your SQL statement>
SELECT * FROM table(dbms_xplan.display);

[Updated on: Sun, 15 March 2015 01:15]

Report message to a moderator

Re: Query execution changes in oracle 11.2.0.4.5 version [message #634753 is a reply to message #634752] Sun, 15 March 2015 01:19 Go to previous messageGo to next message
avineshr
Messages: 14
Registered: September 2012
Location: malaysia
Junior Member
explain plan for mentioned query is as below.

 
---------------------------------------------------
| Id  | Operation          | Name | Rows  | Cost  |
---------------------------------------------------
|   0 | SELECT STATEMENT   |      |     1 |     4 |
|   1 |  FILTER            |      |       |       |
|   2 |   FAST DUAL        |      |     1 |     2 |
|   3 |   TABLE ACCESS FULL| T1   |     1 |     2 |
---------------------------------------------------
 
Note
-----
   - 'PLAN_TABLE' is old version
Re: Query execution changes in oracle 11.2.0.4.5 version [message #634754 is a reply to message #634753] Sun, 15 March 2015 01:24 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

First upgrade your plan table using ?/rdbms/admin/utlxplan.sql.
Also use
select * from table(dbms_xplan.display(format=>'allstats +outline +cost'));

And post the result of:
show parameter optim
show parameter cursor

[Updated on: Sun, 15 March 2015 01:27]

Report message to a moderator

Re: Query execution changes in oracle 11.2.0.4.5 version [message #634755 is a reply to message #634754] Sun, 15 March 2015 01:33 Go to previous messageGo to next message
avineshr
Messages: 14
Registered: September 2012
Location: malaysia
Junior Member
 
----------------------------------------------------
| Id  | Operation          | Name | E-Rows | Cost  |
----------------------------------------------------
|   0 | SELECT STATEMENT   |      |      1 |     4 |
|   1 |  FILTER            |      |        |       |
|   2 |   FAST DUAL        |      |      1 |     2 |
|   3 |   TABLE ACCESS FULL| T1   |      1 |     2 |
----------------------------------------------------
 
Note
-----
   - 'PLAN_TABLE' is old version
   - Warning: basic plan statistics not available. These are only collected when:
       * hint 'gather_plan_statistics' is used for the statement or
       * parameter 'statistics_level' is set to 'ALL', at session or system level



SQL> show parameter optim

NAME                                 TYPE        VALUE
------------------------------------ ----------- ----------------------------
object_cache_optimal_size            integer     102400
optimizer_capture_sql_plan_baselines boolean     FALSE
optimizer_dynamic_sampling           integer     2
optimizer_features_enable            string      11.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
optimizer_use_invisible_indexes      boolean     FALSE
optimizer_use_pending_statistics     boolean     FALSE
optimizer_use_sql_plan_baselines     boolean     TRUE

NAME                                 TYPE        VALUE
------------------------------------ ----------- ----------------------------
plsql_optimize_level                 integer     2



SQL> show parameter cursor

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
cursor_bind_capture_destination      string      memory+disk
cursor_sharing                       string      EXACT
cursor_space_for_time                boolean     FALSE
open_cursors                         integer     600
session_cached_cursors               integer     50
Re: Query execution changes in oracle 11.2.0.4.5 version [message #634757 is a reply to message #634755] Sun, 15 March 2015 01:44 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Michel Cadot wrote on Sun, 15 March 2015 07:24

First upgrade your plan table using ?/rdbms/admin/utlxplan.sql.
Also use
select * from table(dbms_xplan.display(format=>'allstats +outline +cost'));

...

[Updated on: Sun, 15 March 2015 01:45]

Report message to a moderator

Re: Query execution changes in oracle 11.2.0.4.5 version [message #634761 is a reply to message #634750] Sun, 15 March 2015 02:11 Go to previous messageGo to next message
John Watson
Messages: 8985
Registered: January 2010
Location: Global Village
Senior Member
I get no rows returned in 11.2.0.4.0 and 12.1.0.2.0:
SQL> create table T1
  2  (
  3    table_name      VARCHAR2(30),
  4    tablespace_name VARCHAR2(30)
  5  );

Table created.

SQL> SELECT 1  FROM (SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM dual) WHERE col1-col2>0;

no rows selected

SQL> select * from v$version where rownum=1;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

SQL>

SQL>
SQL> create table T1
  2  (
  3    table_name      VARCHAR2(30),
  4    tablespace_name VARCHAR2(30)
  5  );

Table created.

SQL> SELECT 1  FROM (SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM dual) WHERE col1-col2>0;

no rows selected

SQL> select * from v$version where rownum=1;

BANNER                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production              0

SQL>

I woud never exect anythng back, because column name aliases are assigned only at column projection time, not at row selection time. So you can use a column alieas in an ORDER BY clause, but not in a predicate:
SQL>
SQL> SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM dual order by col1;

      COL1       COL2
---------- ----------
         1          0

SQL> SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM dual where col1=1;
SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM dual where col1=1
                                                               *
ERROR at line 1:
ORA-00904: "COL1": invalid identifier


SQL>

Can you show an example of your code working as you think it should?
Re: Query execution changes in oracle 11.2.0.4.5 version [message #634762 is a reply to message #634761] Sun, 15 March 2015 02:28 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

In this case the column aliases are used one query outer from where they are defined, so it is valid.
Or to take your example, it'd be:
SQL> select * from (SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM dual) where col1=1;
      COL1       COL2
---------- ----------
         1          0

In 10.2.0.4 as well as in 11.2.0.1.0, it works as expected:
SQL> SELECT 1  FROM (SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM dual) WHERE col1-col2>0;
         1
----------
         1

1 row selected.

with the inline view as:
SQL> SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM dual;
      COL1       COL2
---------- ----------
         1          0

1 row selected.

I have no version where it does not work, can you test it using "SELECT *" instead of the "SELECT 1" and removing the WHERE clause.

Re: Query execution changes in oracle 11.2.0.4.5 version [message #634764 is a reply to message #634762] Sun, 15 March 2015 02:52 Go to previous messageGo to next message
John Watson
Messages: 8985
Registered: January 2010
Location: Global Village
Senior Member
Yes, the projected column names in a subquey are usable in an outer query predicate. THankyou for the correction.

On both 11.2.0.4.0 and 12.1.0.2.0 I get this same result
SQL> SELECT *  FROM (SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM dual) WHERE col1-col2>0;

      COL1       COL2
---------- ----------
         1          0

SQL> SELECT 1  FROM (SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM dual) WHERE col1-col2>0;

no rows selected

SQL>

And the exec plan stats are:
SQL> SELECT *  FROM (SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM dual) WHERE col1-col2>0;

      COL1       COL2
---------- ----------
         1          0

SQL> select * from table(dbms_xplan.display_cursor(format=>'allstats last +outline +cost'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------
SQL_ID  0cs1hzcgp59h4, child number 1
-------------------------------------
SELECT *  FROM (SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM
dual) WHERE col1-col2>0

Plan hash value: 2068382029

----------------------------------------------------------------------------------------
| Id  | Operation          | Name | Starts | E-Rows | Cost (%CPU)| A-Rows |   A-Time   |
----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |      1 |        |     4 (100)|      1 |00:00:00.01 |
|   1 |  SORT AGGREGATE    |      |      1 |      1 |            |      1 |00:00:00.01 |
|   2 |   TABLE ACCESS FULL| T1   |      1 |     82 |     2   (0)|      0 |00:00:00.01 |
|*  3 |  VIEW              |      |      1 |      1 |     4   (0)|      1 |00:00:00.01 |
|   4 |   FAST DUAL        |      |      1 |      1 |     2   (0)|      1 |00:00:00.01 |
----------------------------------------------------------------------------------------

Outline Data
-------------

  /*+
      BEGIN_OUTLINE_DATA
      IGNORE_OPTIM_EMBEDDED_HINTS
      OPTIMIZER_FEATURES_ENABLE('12.1.0.2')
      DB_VERSION('12.1.0.2')
      OPT_PARAM('optimizer_dynamic_sampling' 0)
      ALL_ROWS
      OUTLINE_LEAF(@"SEL$3")
      OUTLINE_LEAF(@"SEL$2")
      OUTLINE_LEAF(@"SEL$1")
      NO_ACCESS(@"SEL$1" "from$_subquery$_001"@"SEL$1")
      FULL(@"SEL$3" "T1"@"SEL$3")
      END_OUTLINE_DATA
  */

Predicate Information (identified by operation id):
---------------------------------------------------

   3 - filter("COL1"-"COL2">0)


40 rows selected.

SQL> SELECT 1  FROM (SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM dual) WHERE col1-col2>0;

no rows selected

SQL> select * from table(dbms_xplan.display_cursor(format=>'allstats last +outline +cost'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------
SQL_ID  79b0sj36qqugx, child number 1
-------------------------------------
SELECT 1  FROM (SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 FROM
dual) WHERE col1-col2>0

Plan hash value: 2054409553

----------------------------------------------------------------------------------------
| Id  | Operation          | Name | Starts | E-Rows | Cost (%CPU)| A-Rows |   A-Time   |
----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |      1 |        |     4 (100)|      0 |00:00:00.01 |
|*  1 |  FILTER            |      |      1 |        |            |      0 |00:00:00.01 |
|   2 |   FAST DUAL        |      |      0 |      1 |     2   (0)|      0 |00:00:00.01 |
|   3 |   TABLE ACCESS FULL| T1   |      1 |      1 |     2   (0)|      0 |00:00:00.01 |
----------------------------------------------------------------------------------------

Outline Data
-------------

  /*+
      BEGIN_OUTLINE_DATA
      IGNORE_OPTIM_EMBEDDED_HINTS
      OPTIMIZER_FEATURES_ENABLE('12.1.0.2')
      DB_VERSION('12.1.0.2')
      OPT_PARAM('optimizer_dynamic_sampling' 0)
      ALL_ROWS
      OUTLINE_LEAF(@"SEL$3")
      OUTLINE_LEAF(@"SEL$F5BB74E1")
      MERGE(@"SEL$2")
      OUTLINE(@"SEL$1")
      OUTLINE(@"SEL$2")
      FULL(@"SEL$3" "T1"@"SEL$3")
      END_OUTLINE_DATA
  */

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter( IS NOT NULL)


40 rows selected.

SQL>


Re: Query execution changes in oracle 11.2.0.4.5 version [message #634765 is a reply to message #634762] Sun, 15 March 2015 02:55 Go to previous messageGo to next message
avineshr
Messages: 14
Registered: September 2012
Location: malaysia
Junior Member
HI ,

Actual requiremnt is to get the value of col3 based on col1 and col2 so the query will look like below.

Can you please let me know whether you are getting any output for below query.

SELECT col3  FROM (SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 ,4 col3 FROM dual) WHERE col1-col2>0
Re: Query execution changes in oracle 11.2.0.4.5 version [message #634766 is a reply to message #634765] Sun, 15 March 2015 03:22 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

I get it.
Please provide what I requested twice.

Also "test it using "SELECT *" instead of the "SELECT 1" and removing the WHERE clause."
Use SQL*Plus and copy and paste your session as we did.

Re: Query execution changes in oracle 11.2.0.4.5 version [message #634767 is a reply to message #634765] Sun, 15 March 2015 03:26 Go to previous messageGo to next message
John Watson
Messages: 8985
Registered: January 2010
Location: Global Village
Senior Member
If you ALTER SESSION SET OPTIMIZER_MODE=RULE; you will disable the transformation that is losing the row. If you really need to fix this, I tihnk you'll need to use dbms_sqldiag to create a patch. Or hope that Oracle Spport (or Michel Smile ) can come up with omething.
Re: Query execution changes in oracle 11.2.0.4.5 version [message #634768 is a reply to message #634767] Sun, 15 March 2015 03:41 Go to previous messageGo to next message
avineshr
Messages: 14
Registered: September 2012
Location: malaysia
Junior Member
Hi all ,

I agree if I am using "*" , I will get the actual output but we need to know the reason, why output is not coming, if columns are not selected in our select statement.

Adding to above if optimizer mode is rule based then output is coming as expected if I change it to choose then it is failing.

SQL> ALTER SESSION SET optimizer_mode=CHOOSE;

Session altered.

SQL> SELECT col3  FROM (SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 ,4 col3 F
ROM dual) WHERE col1-col2>0;

no rows selected

SQL> ALTER SESSION SET optimizer_mode=RULE;

Session altered.

SQL> SELECT col3  FROM (SELECT 1 col1 , (SELECT COUNT(1) FROM t1) col2 ,4 col3 F
ROM dual) WHERE col1-col2>0;

      COL3
----------
         4

SQL>

Re: Query execution changes in oracle 11.2.0.4.5 version [message #634769 is a reply to message #634768] Sun, 15 March 2015 03:45 Go to previous message
John Watson
Messages: 8985
Registered: January 2010
Location: Global Village
Senior Member
Look at those hints I generated for you, because you could not be bothered to do so Mad Then you will see why you are losing the row.

Really, you have had an awful lot of consultancy for free already. Try doing a bit of research yourself. And, for heavens sake, answer Michel's questions and tell him "thankyou".

[Updated on: Sun, 15 March 2015 03:45]

Report message to a moderator

Previous Topic: Query the newest records
Next Topic: having clause is working before group by , why ?
Goto Forum:
  


Current Time: Tue Aug 19 22:41:07 CDT 2025