Oracle Optimizer bug
I ran a query in Oracle SQL Developer reading exadata database.
I am running a query which is taking 2 hours to run.
The query is as follows:
The plan for the query and the predicate information are also attached.
The problem: optimizer is identifying a join to be merge join cartesian. (operation 12)
But if we remove the filter conditions (mark lewis and account filter from the where clause), the query completes in 2 mins (and with cartesian join).
If i use inline query it does not throw any issues and runs swiftly.
Any ideas on why this is happening will be appreciated.
two things:
wrong forum, try the SQL and PL/SQL community
the OTN Community is not for bugs, please open a Service Request with My Oracle Support
Similar Messages
-
This listing below demonstrates a bug in the Oracle optimizer that causes incorrect results to be returned after a table is analyzed. Rule based optimizer gives correct results.
Under cost-based optimization the predicate includes a condition from a check constraint on a nullable field. When the value of this field is NULL the record is excluded from the results even though that record does not violate the check constraint.
I have verified that this bug exists on both RDBMS versions 9.2.0.7.0 and 9.2.0.8.0.
ORA92080>
ORA92080>DROP TABLE test1;
Table dropped.
ORA92080>DROP TABLE test2;
Table dropped.
ORA92080>
ORA92080>CREATE TABLE test1
2 ( id NUMBER NOT NULL
3 , date1 DATE NOT NULL
4 , date2 DATE
5 );
Table created.
ORA92080>
ORA92080>ALTER TABLE test1
2 ADD ( CONSTRAINT test1_chk_date1
3 CHECK ( date1 > TO_DATE( '01-JAN-1960', 'DD-MON-YYYY' ) )
4 );
Table altered.
ORA92080>
ORA92080>ALTER TABLE test1
2 ADD ( CONSTRAINT test1_chk_date2
3 CHECK ( date2 >= date1 )
4 );
Table altered.
ORA92080>
ORA92080>/* date2 is NULL */
ORA92080>INSERT INTO test1 VALUES ( 1, TO_DATE('16-JUN-2005 11:30:01', 'DD-MON-YYYY HH24:MI:SS'), NULL );
1 row created.
ORA92080>
ORA92080>/* date2 is filled in */
ORA92080>INSERT INTO test1 VALUES ( 2
2 , TO_DATE('16-JUN-2005 11:30:01', 'DD-MON-YYYY HH24:MI:SS')
3 , TO_DATE('16-JUN-2005 11:40:01', 'DD-MON-YYYY HH24:MI:SS')
4 );
1 row created.
ORA92080>
ORA92080>CREATE TABLE test2 AS
2 SELECT * FROM test1
3 WHERE 1=2;
Table created.
ORA92080>
ORA92080>ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';
Session altered.
ORA92080>
ORA92080>SELECT * FROM test1;
ID DATE1 DATE2
1 16-JUN-2005 11:30:01
2 16-JUN-2005 11:30:01 16-JUN-2005 11:40:01
2 rows selected.
ORA92080>SELECT * FROM test2;
no rows selected
ORA92080>
ORA92080>/*
DOC>| Since no statistics were gathered, rule-based optimizer will be used.
DOC>| The correct count of two is returned.
DOC>*/
ORA92080>SELECT COUNT(*) FROM test1 t
2 WHERE EXISTS
3 ( SELECT 'X'
4 FROM ( SELECT id, date1
5 FROM test1
6 MINUS
7 SELECT id, date1
8 FROM test2
9 ) i
10 WHERE i.id = t.id
11 AND i.date1 = t.date1
12 );
COUNT(*)
2
1 row selected.
ORA92080>
ORA92080>EXPLAIN PLAN FOR
2 SELECT COUNT(*) FROM test1 t
3 WHERE EXISTS
4 ( SELECT 'X'
5 FROM ( SELECT id, date1
6 FROM test1
7 MINUS
8 SELECT id, date1
9 FROM test2
10 ) i
11 WHERE i.id = t.id
12 AND i.date1 = t.date1
13 );
Explained.
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | | | |
| 1 | SORT AGGREGATE | | | | |
|* 2 | FILTER | | | | |
| 3 | TABLE ACCESS FULL | TEST1 | | | |
| 4 | VIEW | | | | |
| 5 | MINUS | | | | |
| 6 | SORT UNIQUE | | | | |
|* 7 | TABLE ACCESS FULL| TEST1 | | | |
| 8 | SORT UNIQUE | | | | |
|* 9 | TABLE ACCESS FULL| TEST2 | | | |
Predicate Information (identified by operation id):
2 - filter( EXISTS (SELECT 0 FROM ( (SELECT "TEST1"."ID"
"ID","TEST1"."DATE1" "DATE1" FROM "TEST1" "TEST1" WHERE
"TEST1"."DATE1"=:B1 AND "TEST1"."ID"=:B2)MINUS (SELECT "TEST2"."ID"
"ID","TEST2"."DATE1" "DATE1" FROM "TEST2" "TEST2" WHERE
"TEST2"."DATE1"=:B3 AND "TEST2"."ID"=:B4)) "I"))
7 - filter("TEST1"."DATE1"=:B1 AND "TEST1"."ID"=:B2)
9 - filter("TEST2"."DATE1"=:B1 AND "TEST2"."ID"=:B2)
Note: rule based optimization
28 rows selected.
ORA92080>
ORA92080>BEGIN
2 DBMS_STATS.GATHER_TABLE_STATS
3 ( ownname => USER,
4 tabname => 'TEST2',
5 estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE,
6 cascade => TRUE
7 );
8 END;
9 /
PL/SQL procedure successfully completed.
ORA92080>
ORA92080>/*
DOC>| This is the identical query as above. With statistics gathered, the
DOC>| cost-based optimizer is used. An incorrect count of 1 is returned.
DOC>*/
ORA92080>SELECT COUNT(*) FROM test1 t
2 WHERE EXISTS
3 ( SELECT 'X'
4 FROM ( SELECT id, date1
5 FROM test1
6 MINUS
7 SELECT id, date1
8 FROM test2
9 ) i
10 WHERE i.id = t.id
11 AND i.date1 = t.date1
12 );
COUNT(*)
1
1 row selected.
ORA92080>
ORA92080>/* Using rule-based optimizer, the result is correct. */
ORA92080>SELECT /*+ RULE */ COUNT(*) FROM test1 t
2 WHERE EXISTS
3 ( SELECT 'X'
4 FROM ( SELECT id, date1
5 FROM test1
6 MINUS
7 SELECT id, date1
8 FROM test2
9 ) i
10 WHERE i.id = t.id
11 AND i.date1 = t.date1
12 );
COUNT(*)
2
1 row selected.
ORA92080>
ORA92080>EXPLAIN PLAN FOR
2 SELECT COUNT(*) FROM test1 t
3 WHERE EXISTS
4 ( SELECT 'X'
5 FROM ( SELECT id, date1
6 FROM test1
7 MINUS
8 SELECT id, date1
9 FROM test2
10 ) i
11 WHERE i.id = t.id
12 AND i.date1 = t.date1
13 );
Explained.
ORA92080>
ORA92080>SET ECHO OFF
Wrote file reset.sql
Session altered.
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 1 | 44 | 11 |
| 1 | SORT AGGREGATE | | 1 | 44 | |
|* 2 | HASH JOIN SEMI | | 1 | 44 | 11 |
| 3 | TABLE ACCESS FULL | TEST1 | 82 | 1804 | 2 |
| 4 | VIEW | | 1 | 22 | 8 |
| 5 | MINUS | | | | |
| 6 | SORT UNIQUE | | 1 | 31 | |
|* 7 | TABLE ACCESS FULL| TEST1 | 1 | 31 | 2 |
| 8 | SORT UNIQUE | | 1 | 22 | |
|* 9 | TABLE ACCESS FULL| TEST2 | 1 | 22 | 2 |
Predicate Information (identified by operation id):
2 - access("I"."ID"="T"."ID" AND "I"."DATE1"="T"."DATE1")
7 - filter("TEST1"."DATE1">TO_DATE(' 1960-01-01 00:00:00',
'syyyy-mm-dd hh24:mi:ss') AND "TEST1"."DATE2">TO_DATE(' 1960-01-01
00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
9 - filter("TEST2"."DATE1">TO_DATE(' 1960-01-01 00:00:00',
'syyyy-mm-dd hh24:mi:ss'))
Note: cpu costing is off
27 rows selected.
ORA92080>/*
DOC>| Workaround: change the check constraint on the test1 table that is causing the problem.
DOC>*/
ORA92080>ALTER TABLE test1
2 DROP CONSTRAINT test1_chk_date2;
Table altered.
ORA92080>
ORA92080>ALTER TABLE test1
2 ADD ( CONSTRAINT test1_chk_date2
3 CHECK ( date2 >= date1 OR date2 IS NULL )
4 EXCEPTIONS INTO exceptions
5 );
Table altered.
ORA92080>
ORA92080>SELECT COUNT(*) FROM test1 t
2 WHERE EXISTS
3 ( SELECT 'X'
4 FROM ( SELECT id, date1
5 FROM test1
6 MINUS
7 SELECT id, date1
8 FROM test2
9 ) i
10 WHERE i.id = t.id
11 AND i.date1 = t.date1
12 );
COUNT(*)
2
1 row selected.
ORA92080>
ORA92080>EXPLAIN PLAN FOR
2 SELECT COUNT(*) FROM test1 t
3 WHERE EXISTS
4 ( SELECT 'X'
5 FROM ( SELECT id, date1
6 FROM test1
7 MINUS
8 SELECT id, date1
9 FROM test2
10 ) i
11 WHERE i.id = t.id
12 AND i.date1 = t.date1
13 );
Explained.
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 1 | 44 | 11 |
| 1 | SORT AGGREGATE | | 1 | 44 | |
|* 2 | HASH JOIN SEMI | | 1 | 44 | 11 |
| 3 | TABLE ACCESS FULL | TEST1 | 409 | 8998 | 2 |
| 4 | VIEW | | 20 | 440 | 8 |
| 5 | MINUS | | | | |
| 6 | SORT UNIQUE | | 20 | 440 | |
|* 7 | TABLE ACCESS FULL| TEST1 | 20 | 440 | 2 |
| 8 | SORT UNIQUE | | 1 | 22 | |
|* 9 | TABLE ACCESS FULL| TEST2 | 1 | 22 | 2 |
Predicate Information (identified by operation id):
2 - access("I"."ID"="T"."ID" AND "I"."DATE1"="T"."DATE1")
7 - filter("TEST1"."DATE1">TO_DATE(' 1960-01-01 00:00:00',
'syyyy-mm-dd hh24:mi:ss'))
9 - filter("TEST2"."DATE1">TO_DATE(' 1960-01-01 00:00:00',
'syyyy-mm-dd hh24:mi:ss'))
Note: cpu costing is off
26 rows selected.
ORA92080>Justin,
Thanks for the reply. I have sent this test case to my DBA who may submit it to Metalink.
Since I have found and implemented a workaround, I can wait for the next service release. I just thought that this might be of interest to other Oracle users.
My work-around (buried near the end of my original post) was to modify all check constraints that fit the pattern:
( not_nullable_column condition IS TRUE )
AND ( nullable_column condition IS TRUE )
To:
( not_null_column condition IS TRUE )
AND ( nullable_column condition IS TRUE OR nullable_column IS NULL )
Redefining a check constraint in this way prevents it from being used in the optimizer's predicate.
If someone at Oracle Support wanted to submit code that identifies such potential problem constraints in the data dictionary, that would be great too.
- Doug -
Is this Oracle Reports bug – "break order property" in "group above" report
Is this Oracle Reports bug – “break order property” in "group above" report
Could anybody confirm that in "group above" report, we could only order the brake column's values with ""none" or "ascending" or "descending" provided by "break order property"?
In the following example, “Dept” is brake column. Oracle Reports allows us to order values in “Dept” with “descending” provided by “break order property”:
Dept 30
job ename salary
xxx xxx xxx
xxx xxx xxx
Dept 20
job ename salary
xxx xxx xxx
xxx xxx xxx
Dept 10
job ename salary
xxx xxx xxx
xxx xxx xxx
or “ascending” provided by “break order property”:
Dept 10
job ename salary
xxx xxx xxx
xxx xxx xxx
Dept 20
job ename salary
xxx xxx xxx
xxx xxx xxx
Dept 30
job ename salary
xxx xxx xxx
xxx xxx xxx
I need to do:
Dept 20
job ename salary
xxx xxx xxx
xxx xxx xxx
Dept 10
job ename salary
xxx xxx xxx
xxx xxx xxx
Dept 30
job ename salary
xxx xxx xxx
xxx xxx xxx
Could I do this? Could anybody confirm that we could never ever do this, or If yes, how?
Millions of thanks for advice.
M.Z.
Edited by: jielan on Sep 18, 2010 8:23 AMWhy should that be a bug? You have a custom requirement and have to find a way to fulfill it. But, what is your actual sorting order? Do you have only this three departments? If so, you could add an addtional column in your query like
DECODE(DEPT, 20, 1, 10, 2, 30, 3, 4) SORTINGput that column in the same group as dept and sort after that new column. -
Optimization bug with C++ inlining
Hi,
While evaluating Sun Studio 11 I have identified an optimization bug with C++ inlining.
The bug can easily be reproduced with the small program below. The program produces
wrong results with -xO2, because an inline access function always returns the value 0.0
instead of the value given on the commandline:
djerba{ru}16 : CC -o polybug polybug.cc
djerba{ru}17 : ./polybug 1.0
coeff(0): 1.000000
djerba{ru}18 : CC -o polybug -xO2 polybug.cc
djerba{ru}19 : ./polybug 1.0
coeff(0): 0.000000 <<<<<<<<<< wrong, should be 1.000000This occurs only with optimization level O2; levels below or above O2 don't
exhibit the bug.
Compiler version is
Sun C++ 5.8 Patch 121017-01 2005/12/11
on Solaris 8 / Sparc.
I include a preliminary analysis at the end.
Best Regards
Dieter R.
-------------------- polybug.cc -------------------------
// note: this may look strange, but this is a heavily stripped down
// version of actual working application code...
#include <stdio.h>
#include <stdlib.h>
class Poly {
public:
// constructor initializes number of valid coefficients to zero:
Poly() { numvalid = 0; };
~Poly() {};
// returns coefficient with index j, if valid. Otherwise returns 0.0:
double coeff(int j) {
if (j < numvalid) {
return coefficients[j];
} else {
return 0.0;
// copies contents of this Object to other Poly:
void getPoly(Poly& q) { q = *this; };
// data members:
// valid coefficients: 0 ... (numvalid - 1)
double coefficients[6];
int numvalid;
void troublefunc(Poly* pC) {
// copies Poly-Object to local Poly, extracts coefficient
// with index 0 and prints it. Should be the value given
// on commandline.
// Poly constructor, getPoly and coeff are all inline!
if (pC) {
Poly pol;
pC->getPoly(pol);
printf("coeff(0): %f\n",pol.coeff(0));
int main(int argc,char* argv[]) {
double d = atof(argv[1]);
// creates Poly object and fills coefficient with index
// 0 with the value given on commandline
Poly* pC = new Poly;
pC->coefficients[0] = d;
pC->numvalid = 1;
troublefunc(pC);
return 0;
The disassembly fragment below shows that the access function coeff(0), instead
of retrieving coefficient[0] simply returns the fixed value 0.0 (presumably because the
optimizer "thinks" numvalid holds still the value 0 from the constructor and that therefore
the comparison "if (i < numvalid)" can be omitted).
Note: disassembly created from code compiled with -features=no%except for simplicity!
00010e68 <___const_seg_900000102>:
... holds the value 0.0
00010e80 <__1cLtroublefunc6FpnEPoly__v_>:
10e80: 90 90 00 08 orcc %g0, %o0, %o0 if (pC) {
10e84: 02 40 00 14 be,pn %icc, 10ed4
10e88: 9c 03 bf 50 add %sp, -176, %sp
local Poly object at %sp + 120
numvalid at %sp + 0xa8 (168)
10e8c: c0 23 a0 a8 clr [ %sp + 0xa8 ] Poly() { numvalid = 0; };
pC->getPoly(pol):
loop copies *pC to local Poly object
10e90: 9a 03 a0 80 add %sp, 0x80, %o5
10e94: 96 10 20 30 mov 0x30, %o3
10e98: d8 5a 00 0b ldx [ %o0 + %o3 ], %o4
10e9c: 96 a2 e0 08 subcc %o3, 8, %o3
10ea0: 16 4f ff fe bge %icc, 10e98
10ea4: d8 73 40 0b stx %o4, [ %o5 + %o3 ]
pol.coeff(0):
load double value 0.0 at
___const_seg_900000102 in %f0
(and address of format string in %o0)
10ea8: 1b 00 00 43 sethi %hi(0x10c00), %o5
10eac: 15 00 00 44 sethi %hi(0x11000), %o2
10eb0: c1 1b 62 68 ldd [ %o5 + 0x268 ], %f0
10eb4: 90 02 a0 ac add %o2, 0xac, %o0
10eb8: 82 10 00 0f mov %o7, %g1
store 0.0 in %f0 to stack and load it
from there to %o1/%o2
10ebc: c1 3b a0 60 std %f0, [ %sp + 0x60 ]
10ec0: d2 03 a0 60 ld [ %sp + 0x60 ], %o1
10ec4: d4 03 a0 64 ld [ %sp + 0x64 ], %o2
10ec8: 9c 03 a0 b0 add %sp, 0xb0, %sp
call printf
10ecc: 40 00 40 92 call 21114 <_PROCEDURE_LINKAGE_TABLE_+0x54>
10ed0: 9e 10 00 01 mov %g1, %o7
10ed4: 81 c3 e0 08 retl
10ed8: 9c 03 a0 b0 add %sp, 0xb0, %sp
Hmmm... This seems to stress this formatting tags thing to its limits...Thanks for confirming this.
No, this happens neither in an Open Source package nor in an important product. This is an internal product, which is continuously developed with Sun Tools since 1992 (with incidents like this one being very rare).
I am a bit concerned with this bug though, because it might indicate a weakness in the area of C++ inlining (after all, the compiler fails to correctly aggregate a sequence of three fairly simple inline functions, something which is quite common in our application). If, on the other hand, this is a singular failure caused by unique circumstances which we have hit by sheer (un)luck, it is always possible to work around this: explicitly defining a assignment operator instead of relying on the compiler-generated one is sufficient to make the bug go away. -
Which column first filter by oracle optimizer
Can somebody help in understand which column first filter by oracle optimizer in below example and why?
select * from emp where ENAME ='FORD'
AND SAL=3000 ;Hi,
Look at the EXPLAIN PLAN.
Other things being equal, if there are more distinct values of ename than of sal, then it's probably checking for 'FORD' first.
For example, say the table has 100,000 rows, and there are 10,000 distinct enames, and 100 distinct sals, both ename and sal are indexed, but there is no combined index.
If you search by sal first, that means you'll expect around 1,000 rows from the index search, and then you'll have to test each of those 1,000 rows for the right ename.
If you search by ename, first, that means you'll expect around 10 rows from the index search, and you'll only have to test each of those 10 rows for the right sal.
The order in which the conditions were written will matter.
Edited by: Frank Kulash on Apr 2, 2012 7:54 AM -
Not a GROUP BY expression - Oracle 10g bug?
Hi,
I am geting 00979. 00000 - "not a GROUP BY expression" error on Oracle 10g 10.2.0.4.0 - 64bit Production.
To illustrate my problem I created following example.
Let think I have some shop with clothes. Everytime I sell something, I store this information in the database - storing actual time, clothes type (trousers, socks, ...) and the size of the piece (M, L, XL, ...).
Now, system counts statistics every hour. So it goes thrue the table with sold pieces and counts the number of pieces per clothes type and per size from the beginning of the day. It is important to realize that it is from the beginning of the day. Because of that, the number of sold pieces in the statistical table grows every hour (or is at least on the same value as in previous hour).
Now, from this statistical table I need to make new statistic. I want a statistic how many pieces per size I sold every hour.
I created this query for that:
SELECT TIME, xSIZE, (SOLD - NVL((SELECT SUM(S1.SOLD)
FROM STATISTICS S1
WHERE S1.xSIZE = S.xSIZE
AND TRUNC(S1.TIME, 'HH24') + 1/24 = S.TIME
AND TO_CHAR(S1.TIME, 'HH24') != '23'
AND S1.xSIZE IS NOT NULL
GROUP BY TRUNC(S1.TIME, 'HH24'), S1.xSIZE),0)) SOLD
FROM(
SELECT TRUNC(S.TIME, 'HH24') TIME, S.xSIZE, SUM(S.SOLD) SOLD
FROM STATISTICS S
WHERE S.xSIZE IS NOT NULL
GROUP BY TRUNC(S.TIME, 'HH24'), S.xSIZE
--ORDER BY 1 DESC
) S
ORDER BY TIME DESC, xSIZE ASCFirst I select number of sold pieces per hour per size. To get number of sold pieces for particular hour, I need to substract from this value number of sold pieces from previous hour. I decided to do this with parameter query...
Running the query like this I get "not a GROUP BY expression" error. However if I uncomment the "ORDER BY 1 DESC" statement, the query works. I am pretty sure it has to do something with this line:
AND TRUNC(S1.TIME, 'HH24') + 1/24 = S.TIME
If you modify this query like this:
SELECT TIME, xSIZE, (SOLD - NVL((SELECT SUM(S1.SOLD)
FROM STATISTICS S1
WHERE S1.xSIZE = S.xSIZE
--AND TRUNC(S1.TIME, 'HH24') + 1/24 = S.TIME
AND TO_CHAR(S1.TIME, 'HH24') != '23'
AND S1.xSIZE IS NOT NULL
GROUP BY S1.xSIZE),0)) SOLD
FROM(
SELECT TRUNC(S.TIME, 'HH24') TIME, S.xSIZE, SUM(S.SOLD) SOLD
FROM STATISTICS S
WHERE S.xSIZE IS NOT NULL
GROUP BY TRUNC(S.TIME, 'HH24'), S.xSIZE
--ORDER BY 1 DESC
) S
ORDER BY TIME DESC, xSIZE ASCRemoved joining the tables on truncated time and grouping by the truncated time -> The query does not fail...
And now the best...if you run the first query on Oracle 11g (Release 11.1.0.6.0 - 64bit Production), it works.
Does anybody know why is the first query not working on 10g? Is there some bug or limitation for this server version?
Please don't say me to rewrite the query in another way, I already did it, so it works on 10g as well. I am just curious why it doesn't work on 10g.
Finally here are some data for testing.
CREATE TABLE STATISTICS(
TIME DATE DEFAULT SYSDATE,
TYPE VARCHAR2(20),
xSIZE VARCHAR2(2),
SOLD NUMBER(5,0) DEFAULT 0
INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 2/24, 'T-Shirt', 'M', 10);
INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 2/24, 'Socks', 'M', 3);
INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 2/24, 'T-Shirt', 'L', 1);
INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 2/24, 'Socks', 'L', 50);
INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 2/24, 'Trousers', 'XL', 7);
INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 2/24, 'Socks', 'XL', 3);
INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 1/24, 'T-Shirt', 'M', 13);
INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 1/24, 'Socks', 'L', 60);
INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 1/24, 'Trousers', 'XL', 15);
INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 1/24, 'Socks', 'XL', 6);Edited by: user12047225 on 20.9.2011 23:12
Edited by: user12047225 on 20.9.2011 23:45It is a known issue when optimizer decides to expand in-line view. You can add something (besides ORDER BY you already used) to in-line view to prevent optimizer from expanding it. For example:
SQL> SELECT TIME,
2 xSIZE,
3 (SOLD - NVL(
4 (
5 SELECT SUM(S1.SOLD)
6 FROM STATISTICS S1
7 WHERE S1.xSIZE = S.xSIZE
8 AND TRUNC(S1.TIME, 'HH24') + 1/24 = S.TIME
9 AND TO_CHAR(S1.TIME, 'HH24') != '23'
10 AND S1.xSIZE IS NOT NULL
11 GROUP BY TRUNC(S1.TIME, 'HH24'),
12 S1.xSIZE
13 ),
14 0
15 )
16 ) SOLD
17 FROM (
18 SELECT TRUNC(S.TIME, 'HH24') TIME,
19 S.xSIZE,
20 SUM(S.SOLD) SOLD
21 FROM STATISTICS S
22 WHERE S.xSIZE IS NOT NULL
23 GROUP BY TRUNC(S.TIME, 'HH24'),
24 S.xSIZE
25 --ORDER BY 1 DESC
26 ) S
27 ORDER BY TIME DESC,
28 xSIZE ASC
29 /
SELECT TRUNC(S.TIME, 'HH24') TIME,
ERROR at line 18:
ORA-00979: not a GROUP BY expression
SQL> SELECT TIME,
2 xSIZE,
3 (SOLD - NVL(
4 (
5 SELECT SUM(S1.SOLD)
6 FROM STATISTICS S1
7 WHERE S1.xSIZE = S.xSIZE
8 AND TRUNC(S1.TIME, 'HH24') + 1/24 = S.TIME
9 AND TO_CHAR(S1.TIME, 'HH24') != '23'
10 AND S1.xSIZE IS NOT NULL
11 GROUP BY TRUNC(S1.TIME, 'HH24'),
12 S1.xSIZE
13 ),
14 0
15 )
16 ) SOLD
17 FROM (
18 SELECT TRUNC(S.TIME, 'HH24') TIME,
19 S.xSIZE,
20 SUM(S.SOLD) SOLD,
21 ROW_NUMBER() OVER(ORDER BY SUM(S.SOLD)) RN
22 FROM STATISTICS S
23 WHERE S.xSIZE IS NOT NULL
24 GROUP BY TRUNC(S.TIME, 'HH24'),
25 S.xSIZE
26 --ORDER BY 1 DESC
27 ) S
28 ORDER BY TIME DESC,
29 xSIZE ASC
30 /
TIME XS SOLD
20-SEP-11 L 9
20-SEP-11 M 0
20-SEP-11 XL 11
20-SEP-11 L 51
20-SEP-11 M 13
20-SEP-11 XL 10
6 rows selected.
SQL> Or use subquery factoring (WITH clause) + undocumented hint MATERIALIZE:
SQL> WITH S AS (
2 SELECT /*+ MATERIALIZE */ TRUNC(S.TIME, 'HH24') TIME,
3 S.xSIZE,
4 SUM(S.SOLD) SOLD
5 FROM STATISTICS S
6 WHERE S.xSIZE IS NOT NULL
7 GROUP BY TRUNC(S.TIME, 'HH24'),
8 S.xSIZE
9 --ORDER BY 1 DESC
10 )
11 SELECT TIME,
12 xSIZE,
13 (SOLD - NVL(
14 (
15 SELECT SUM(S1.SOLD)
16 FROM STATISTICS S1
17 WHERE S1.xSIZE = S.xSIZE
18 AND TRUNC(S1.TIME, 'HH24') + 1/24 = S.TIME
19 AND TO_CHAR(S1.TIME, 'HH24') != '23'
20 AND S1.xSIZE IS NOT NULL
21 GROUP BY TRUNC(S1.TIME, 'HH24'),
22 S1.xSIZE
23 ),
24 0
25 )
26 ) SOLD
27 FROM S
28 ORDER BY TIME DESC,
29 xSIZE ASC
30 /
TIME XS SOLD
20-SEP-11 L 9
20-SEP-11 M 0
20-SEP-11 XL 11
20-SEP-11 L 51
20-SEP-11 M 13
20-SEP-11 XL 10
6 rows selected.
SQL> SY. -
Oracle 9 bug (all platforms affected)
Don't have paid support so I don't know where else I can report this bug.
Oracle 9 - all platforms (used to work in Oracle 8).
create table test (k raw(10) primary key, v varchar(10))
create index x on test(k) descending
insert some data
The following select statement will work incorrectly:
select --+ INDEX_ASC(test)
* from test where k > some_value and rownum = 1 order by k
It might work ok if you don't put the hint.
It will work also if you don't have ANY other indexes on that table.
Regards,
SergeyHow big are these tables? I did some tests on a table with around 35,000 rows (I know not big) and the result was returned in 0.2 or 0.4 of a second? Does it need to be faster. How many rows and what response times are you seeing?
SQL> create table t (
2 k raw(20), v varchar2(30),
3 constraint test_pk primary key (k)
4 )
5 /
Table created.
SQL> insert into t select utl_raw.cast_from_number(object_id), object_name from all_objects;
36297 rows created.
SQL> exec dbms_stats.gather_table_stats(user, 't', cascade => true)
PL/SQL procedure successfully completed.
SQL> set autotrace on
SQL> select min(k) from t
2 where k > utl_raw.cast_from_number(10000);
MIN(K)
C302015D
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=5)
1 0 SORT (AGGREGATE)
2 1 FIRST ROW (Cost=2 Card=1815 Bytes=9075)
3 2 INDEX (RANGE SCAN (MIN/MAX)) OF 'TEST_PK' (UNIQUE) (Cost=2 Card=20)
Statistics
0 recursive calls
0 db block gets
2 consistent gets
0 physical reads
0 redo size
210 bytes sent via SQL*Net to client
248 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> edi
Wrote file afiedt.sql
1 select t.* from t,
2 (select min(k) x from t
3 where k > utl_raw.cast_from_number(10000))
4* where k = x
SQL> /
K V
C302015D EXC_FFRPRFUP
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=39)
1 0 NESTED LOOPS (Cost=2 Card=1 Bytes=39)
2 1 VIEW (Cost=1 Card=1 Bytes=12)
3 2 SORT (AGGREGATE)
4 3 FIRST ROW (Cost=2 Card=1815 Bytes=9075)
5 4 INDEX (RANGE SCAN (MIN/MAX)) OF 'TEST_PK' (UNIQUE) (Cost=2 Card=20)
6 1 TABLE ACCESS (BY INDEX ROWID) OF 'T' (Cost=1 Card=1 Bytes=27)
7 6 INDEX (UNIQUE SCAN) OF 'TEST_PK' (UNIQUE)
Statistics
5 recursive calls
0 db block gets
7 consistent gets
0 physical reads
0 redo size
243 bytes sent via SQL*Net to client
248 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> set autotrace off
SQL> select t.* from t,
2 (select min(k) x from t
3 where k > utl_raw.cast_from_number(10000))
4 where k = x
5 /
K V
C302015D EXC_FFRPRFUP
SQL> set timing on
SQL> /
K V
C302015D EXC_FFRPRFUP
Elapsed: 00:00:00.20
SQL> edi
Wrote file afiedt.sql
1 select t.* from t,
2 (select min(k) x from t
3 where k > utl_raw.cast_from_number(15000))
4* where k = x
SQL> /
K V
C3023303 AA_COL
Elapsed: 00:00:00.30
SQL> edi
Wrote file afiedt.sql
1 select * from t
2 where k = (select min(k) x from t
3* where k > utl_raw.cast_from_number(17000))
SQL> /
K V
C3024705 EXC_FFRFSFND
Elapsed: 00:00:00.40
SQL>This
select --+ INDEX_ASC(tablename tablename)
... etc ...is still a lucky accident and is not guaranteed to always give you the correct answer. -
We are trying to execute a simple query of the form
select * from sometable where upper(attr1) like 'WB%' or upper(attr2) like 'WB%' or upper(attr3) like 'WB%'
The data does exist in the table but the query does not return values.
Sometimes the count(*) on that table returns the correct number but the actual select statement does not return data.
We have added a dummy where clause
select * from sometable where upper(attr1) like 'WB%' or upper(attr2) like 'WB%' or upper(attr3) like 'WB%' or lower(attr2) like 'WB%' and the data does show up.
We are on Oracle 11g 11.2.0.2 and have migrated recently from 10g. And this issue has started appearing after the migration.
Any thoughts on what could be causing this issue ?
Thanks
Surya
Edited by: Surya on 09-Mar-2011 06:11user11180582 wrote:
We have added a dummy where clause
select * from sometable where upper(attr1) like 'WB%' or upper(attr2) like 'WB%' or upper(attr3) like 'WB%' or lower(attr2) like 'WB%' and the data does show up. Hm. difficult but I doubt that you have a bug. I guess you have either some strange values or there is something in the full statement that is missing in your example.
For example please be aware that the AND operator has a higher priority then the OR operator (is this way since oracle 7 at least).
So if your real statement would include an and condition, this could produce unwanted outcome.
select * from sometable
where upper(attr1) like 'WB%'
or upper(attr2) like 'WB%'
or upper(attr3) like 'WB%'
and lower(attr5) = 'XY' This is identical to:
select * from sometable
where upper(attr1) like 'WB%'
or upper(attr2) like 'WB%'
or (upper(attr3) like 'WB%' and lower(attr5) = 'XY' )But usually you want
select * from sometable
where (upper(attr1) like 'WB%' or upper(attr2) like 'WB%' or upper(attr3) like 'WB%')
and lower(attr5) = 'XY' Some additon. Your condition could also be written like this. Maybe this helps to find the real cause of the error.
select * from sometable
where 'WB' in (substr(upper(attr1),1,2)
,substr(upper(attr2),1,2)
,substr(upper(attr3),1,2)
)I find this often to be better readable then a long LIKE + OR expression. -
Oracle 11g bug for column ambigously defined error
I have below format query running on Oracle 10g without any issues
select col1
from (select col1
from (select 'A' col1
from dual)
) v1
inner join (select col1 as col2
from (select 'A' col1
from dual)
) v2
on (v1.col1=v2.col2);
When I run the exact same query on Oracle 11g I get column ambiguously defined error. But when I change the query to as below it works fine on 11g
select v1.col1
from (select col1
from (select 'A' col1
from dual)
) v1
inner join (select col1 as col2
from (select 'A' col1
from dual)
) v2
on (v1.col1=v2.col2);
Is it because 11g ignores column alias in my inner queries.I'd tend to agree that this seems to be a bug in 11.1.0.7 (at least, that's the version I'm running it in)
It's not even that Oracle doesn't know about the column aliases, you can remove the aliases in the ON without a problem, i.e.
SELECT v1.col1
FROM
(SELECT col1 FROM
(SELECT 'A' col1 FROM dual
) v1
INNER JOIN
(SELECT col1 AS col2 FROM
(SELECT 'A' col1 FROM dual
) v2
ON (col1=col2);works fine. Using the old join syntax also seems to work fine
SELECT col1
FROM
(SELECT col1 FROM
(SELECT 'A' col1 FROM dual
) v1,
(SELECT col1 AS col2 FROM
(SELECT 'A' col1 FROM dual
) v2
WHERE (col1=col2);So it appears that something in the SQL 99 parser is broken. Have you logged a bug in Metalink?
Justin -
Want answer from Oracle about bug in Login Config Provider...
Hello. Several days ago I posted a question about a potential bug in oracle.security.jazn.spi.LoginConfigProvider. No responses so far - Could someone at Oracle please comment about this? I am preparing to document my own solution, but I would prefer to use Oracle's - if I can make it work.
Is this a bug or am I doing something wrong. The thread with the details is below...
Bug in oracle.security.jazn.spi.LoginConfigProvider?
Thanks
ChrisYou should probably post in Metalink for 'official' responses
-
Dear OTN people,
when playing around with Oracle 8i EE for Linux I have found
several problems:
The following bugs/problems I have encountered are:
I have already applied sucessfully the patch to 8.1.5.0.1
1. $ORACLE_HOME/bin/osfind is a SPARC executable
2. $ORACLE_HOME/bin/osagent is a SPARC executable
3. $ORACLE_HOME/bin/locserv is a SPARC executable
4. $ORACLE_HOME/bin/vbj references "whence" which is not
available on Linux
5. alert files always contain: "Load indicator not supported by
OS!"
6. when trying ejb samples you cannot use jdk 1.1.7 or above
since oracle jvm seems to test for the version number: this
should
at least be documented. Better would be to remove this check.
Java is Java, and a jdk 1.1.6 and 1.1.7 should be compatible in
terms of functionality. I know this is not reality...
7. the THREADS option for all java tools should be configurable
centrally, and it should not only be green and native
but also be "empty", so one can use IBM jdk1.1.6 which is VERY
good. It simply does not accept -native or -green since it
is a real native implementation. I will send a request to IBM for
adding dummy options as well...
8. It is annoying that some java tools require JRE wheras some
require JDK (rt.jar vs. classes.zip). Could you unify this?
9. Please do not hardcode the jre/jdk directories. Many
distributions do not have java in /usr/local. Make it
installation configurable. It could even be detected
automatically via "which jre" ;-)
10. /javavm/demo/examples/ejb/applets/EJBClubMed example give
this error:
clubMedClient/ClubMedClient.java:18: Class
netscape.security.PrivilegeManager not found in import.
import netscape.security.PrivilegeManager;
Having those problems I am not able to test the corba stuff
supplied in the javavm/demo directory.
I really appreciate very much Oracle's commitment to Linux, so
please go ahead and fix those problems to make all your users
happy ;-)
Greetings
Marcus
nullSingle quotes must be doubled in SQL statements to be legal. I've filed Bug# 3574900 for us to do a better job on fixing up this case in the future, but there's an easy workaround idea for now.
If you don't want the user to have to know/remember this, you could override the getViewCriteriaClause() method in your ViewObjectImpl class, and "fix up" the view criteria attributes to double-up occurrences of single apostrophe's before returning super.getViewCriteriaClause().
Here's a quick web log entry on it with some sample code:
http://radio.weblogs.com/0118231/2004/04/16.html#a276 -
Oracle Optimizer Mode Choose / Rule
Hello,
we have a strange behavior with Oracle 9.2
We have a application doing
SELECT to_char(COLUMNNAME)
FROM
VIEW WHERE ROWNUM = 1
This statement needs 75 seconds executed on the server within the application.
call count cpu elapsed disk query current rows
Parse 68 0.01 0.02 1 108 0 0
Execute 136 0.14 0.14 0 0 0 0
Fetch 68 68.74 75.64 119587 181628 2 68
total 272 68.89 75.81 119588 181736 2 68
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 25
Rows Row Source Operation
1 COUNT STOPKEY
1 HASH JOIN
524213 TABLE ACCESS FULL TABLEA
6 INDEX FAST FULL SCAN INDEX (object id 7026)
Optimizer mode is CHOOSE and we have generated Statistics.
When we switch to RULE the SQL will perform within millseconds
call count cpu elapsed disk query current rows
Parse 68 0.01 0.00 0 2 0 0
Execute 68 0.00 0.00 0 0 0 0
Fetch 68 0.01 0.05 68 476 0 68
total 204 0.02 0.05 68 478 0 68
Misses in library cache during parse: 1
Optimizer goal: RULE
Parsing user id: 25
Rows Row Source Operation
1 COUNT STOPKEY
1 NESTED LOOPS
1 TABLE ACCESS FULL TABLEA
1 INDEX UNIQUE SCAN INDEX (object id 7026)
Even when executing this statement within SQLPLUS on the server it takes 1 second (even too long but not 70 seconds).
Has anybody a hint where to look ?? I´m really confused.
Kind Regards,
KlausOptimizer mode choose with statistics effectively means ALL_ROWS. So I suspect that this probably is the reason why Oracle uses full scans and hash joins. On the other hand rownum = 1 should give the optimizer info that you only need 1 row back. So probably try with either optimizer_mode = first_rows_1 or hint first_rows(1) and see what happens.
Gints Plivna
http://www.gplivna.eu -
Blob type parameter in procedure for display issue. Oracle portal bug?
Hi Guy,
I am not sure this is a bug or not for oracle portal.
I have a table that have a column type as blob.
by oracle portal10g, this column should be display as Item Type Upload (Binary) at Item Level Options.
We can create a form to display this file and modify it.
However, It can not to use a procedure with a blob column to create the same form as above. we can not find Item Type as Upload (Binary) in form. if we choose text area.
We will get a error "ORA-01403: no data found (WWV-11230)"
We find this issue during convert clob column to blob type in procedure for a form using.
This is a simple procedure.
See below source codes:
Thanks for any help.
create or replace Procedure test_file
( p_DOCUMENT_ID IN OUT file.DOCUMENT_ID%type,
p_USER_ID out file.USER_ID%type,
p_DOCUMENT_NAME out file.DOCUMENT_NAME%type,
p_DOCUMENT out blob,
p_CREATED_BY out file.CREATED_BY%type,
p_CREATED_TIMESTAMP out file.CREATED_TIMESTAM%type,
p_UPDATED_BY out file.UPDATED_BY%type,
p_UPDATED_TIMESTAMP out file.UPDATED_TIMESTAMP%type,
p_DOCUMENT_DESC out file.DOCUMENT_DESC%type) as
L_DOCUMENT BLOB;
begin
begin
SELECT USER_ID , DOCUMENT_NAME,DOCUMENT, DOCUMENT_MIME, CREATED_BY, CREATED_TIMESTAMP,
UPDATED_BY , UPDATED_TIMESTAMP, DOCUMENT_DESC
INTO p_USER_ID , p_DOCUMENT_NAME,L_DOCUMENT, p_DOCUMENT_MIME, p_CREATED_BY, p_CREATED_TIMESTAMP,
p_UPDATED_BY , p_UPDATED_TIMESTAMP, p_DOCUMENT_DESC
FROM file
WHERE DOCUMENT_ID = p_DOCUMENT_ID;
exception
when NO_DATA_FOUND then
null;
end;
p_DOCUMENT :=L_DOCUMENT;
exception
when others then
null;
end;Hi,
I have created a vo with transient attributes and attached the vo to the am.
But when I am trying to insert the row from my collection, it is giving me '
oracle.jbo.NoDefException: JBO-25058: Definition of resField of type Attribute not found in ResVO
But I have the transient attribute resField in my ResVO and I attached the same to AM also
I am trying to get the VO in my controller like the below:
OAViewObject resvo = (OAViewObject) am.findViewObject("ResVO");
if(vo==null)
resvo = am.createViewObject("ResVO","xxcust.oracle.apps.xxcust.server.ResVO");
if(vo!= null)
resvo.executeQuery();
//Creating and inserting values into the vo
Row row = resvo.createRow();
resvo.insertRow(row);
row.setAttribute("resField", "AB");
row.setAttribute("Value", "CD");
row.setAttribute("Desc", "Test");
When I am running my page, I am getting the
oracle.jbo.NoDefException: JBO-25058: Definition of resField of type Attribute not found in ResVO
I checked the spelling and the attribute name is correct.
Is it the problem with VO having all the transient attributes or am I missing something?
I appreciate your help... -
I would like to find a copy of the APEX bug tracker that used to be on the apex.oracle.com web page. Does anyone know where I can find that?
I know they moved this to the cloud and I am exploring that but I would also like a local copy to experiment with.I have a copy
source
https://docs.google.com/open?id=0B_eVXQ_oe4tsSXNXUVpGQkNURWF6TmthTEQ4Nnpadw
readme
https://docs.google.com/document/d/1e3PerYZZ4K-lzMA85SCgVPpUyDSA2_I3ARuy0nQpJIQ/edit
Scott -
I am using the Flex Builder 2.01 Eclipse plugin on a MacBook
Pro. I have some code which takes an object tree and recursively
wraps all of the Array properties of objects to ArrayCollections.
So for example, the tree starts with an object Foo, which has a
bunch of properties on it. One of these properties could be an
Array. This Array property will be replaced by an ArrayCollection,
and then for each object in the array, the same process is
performed. Here is some example code:
public static function convertObject( o:Object ):Object
var classInfo:XML = describeType( o );
if ( [email protected]() == "Object" )
for ( var key:String in o )
var value:Object = o[key];
if ( value is Array )
o[key] = convertToArrayCollection( o, value as Array );
return o;
public static function convertToArrayCollection(
parent:Object, value:Array ):ArrayCollection
var arrayCollection:ArrayCollection = new ArrayCollection();
arrayCollection.source = value;
for ( var i:int = 0; i < value.length; i++ )
convertObject( value
, changeListener );
return ArrayCollection(arrayCollection);
So, when I use the default compiler settings in Flex Builder
2.01, this will intermittently fail. The behavior I get is that
when I iterate through the properties of the object I am
converting, some of the properties are not there, and other
properties are duplicated. So for example, if my object has these
properties:
foo
bar
myarray
When I iterate through all the properties, I get
foo
bar
foo
bar
instead of
foo
bar
myarray
I first tried to debug this issue, thinking there was some
problem with my code. But whenever I ran the debug version, I
didn't see the problem. Finally, under compiler options, I set
-debug=true and -optimize=false and the problem appears to have
went away. So, it appears that there is some problem with the
optimization in the compiler.Thanks for confirming this.
No, this happens neither in an Open Source package nor in an important product. This is an internal product, which is continuously developed with Sun Tools since 1992 (with incidents like this one being very rare).
I am a bit concerned with this bug though, because it might indicate a weakness in the area of C++ inlining (after all, the compiler fails to correctly aggregate a sequence of three fairly simple inline functions, something which is quite common in our application). If, on the other hand, this is a singular failure caused by unique circumstances which we have hit by sheer (un)luck, it is always possible to work around this: explicitly defining a assignment operator instead of relying on the compiler-generated one is sufficient to make the bug go away.
Maybe you are looking for
-
Second Flat Panel not detecting...
All of our Macs are connected to dual 20" viewsonic flat panels. I relocated one yesterday, leaving the original flat panels and hooking the Mac up to another set of dual fps (same model). I had no problem with the display coming back up and recogniz
-
How to calculate the summery values in the query
Hi, I have facing a typical problem , I can able to get the values for the detailed one plant material qyt a x 100 y 50 b z 50 result 200 when I am removed the drilldown f
-
Best way to pack templates in WAR ?
Hi all, I want to deploy a war file on to a bunch of different tomcat servers. There are java class files within my war file that need to read from templates (eg. emails, xml files, html pages, whatever). What is the best way to do this? Where should
-
Player's position slider (Thread not owner)
Hi every1, I've a thread that sets a slider value with the player's time in secods,but in case the slider Knob is dragged by the user the thread should wait and player's time should be set as per the value dragged by the user. But the wait() method i
-
When I open a folder, I can see the size of the files in the folder. However. When I search for a file in FINDER, it does not show the size of the file. And I can find no option to make it show the size of the file. I would like to see the size of th