![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I maintain a PHP-driven web app that's been deployed for several customers that have a variety of Oracle environments. One of them has reported that one of the modules is not working and I've traced back the issue to a very specific SQL query. The query itself does not use a complicate syntax; it's only a bunch of table joins: SELECT DISTINCT regular_table.regular_table_id AS c0, * * * * additional_table_1.foo AS c1, * * * * additional_table_2.bar AS c2, * * * * TO_CHAR(regular_table.start_date, 'DD/MM/YYYY') AS c3, * * * * ........ * * * * temporary_table.sort_order AS sort_order_ FROM temporary_table INNER JOIN regular_table ON temporary_table.regular_table_id=regular_table.reg ular_table_id LEFT JOIN additional_table_1 ON regular_table.regular_table_id=additional_table_1. regular_table_id LEFT JOIN additional_table_2 ON regular_table.additional_table_2_id=additional_tab le_2.additional_table_2_id ........ ORDER BY sort_order_; I assume the issue is probably related to having an insane amount of table joins. I'm testing from SQL*Plus with an empty "temporary_table" table so no rows should be returned. When I run a simplified version of the query the result comes out immediately: SELECT DISTINCT regular_table.regular_table_id AS c0, * * * * additional_table_1.foo AS c1, * * * * TO_CHAR(regular_table.start_date, 'DD/MM/YYYY') AS C3, * * * * temporary_table.sort_order AS sort_order_ FROM temporary_table INNER JOIN regular_table ON temporary_table.regular_table_id=regular_table.reg ular_table_id LEFT JOIN additional_table_1 ON regular_table.regular_table_id=additional_table_1. regular_table_id ORDER BY sort_order_; As I add additional LEFT JOIN clauses one by one, the execution time increase exponentially. Once I manage to successfully run a query that takes, e.g., 10 minutes, successive executions run almost instantly! That leads me to think that the bottleneck is the query optimizer itself... But, is that even possible? The server runs "Oracle9i Release 9.2.0.1.0 - 64bit Production"; I heard the DBA mention something about "cluster" but that's all I know. Any idea of what to look next? -- --http://alvaro.es- Álvaro G. Vicario - Burgos, Spain -- Mi sitio sobre programación web:http://borrame.com -- Mi web de humor satinado:http://www.demogracia.com -- |
|
""Any idea of what to look next? |
|
"Oracle9i Release 9.2.0.1.0 - 64bit Production"; I heard the DBA mention...." |
#3
| |||
| |||
|
|
I maintain a PHP-driven web app that's been deployed for several customers that have a variety of Oracle environments. One of them has reported that one of the modules is not working and I've traced back the issue to a very specific SQL query. The query itself does not use a complicate syntax; it's only a bunch of table joins: SELECT DISTINCT regular_table.regular_table_id AS c0, * * * * additional_table_1.foo AS c1, * * * * additional_table_2.bar AS c2, * * * * TO_CHAR(regular_table.start_date, 'DD/MM/YYYY') AS c3, * * * * ........ * * * * temporary_table.sort_order AS sort_order_ FROM temporary_table INNER JOIN regular_table ON temporary_table.regular_table_id=regular_table.reg ular_table_id LEFT JOIN additional_table_1 ON regular_table.regular_table_id=additional_table_1. regular_table_id LEFT JOIN additional_table_2 ON regular_table.additional_table_2_id=additional_tab le_2.additional_table_2_i*d ........ ORDER BY sort_order_; I assume the issue is probably related to having an insane amount of table joins. I'm testing from SQL*Plus with an empty "temporary_table" table so no rows should be returned. When I run a simplified version of the query the result comes out immediately: SELECT DISTINCT regular_table.regular_table_id AS c0, * * * * additional_table_1.foo AS c1, * * * * TO_CHAR(regular_table.start_date, 'DD/MM/YYYY') AS C3, * * * * temporary_table.sort_order AS sort_order_ FROM temporary_table INNER JOIN regular_table ON temporary_table.regular_table_id=regular_table.reg ular_table_id LEFT JOIN additional_table_1 ON regular_table.regular_table_id=additional_table_1. regular_table_id ORDER BY sort_order_; As I add additional LEFT JOIN clauses one by one, the execution time increase exponentially. Once I manage to successfully run a query that takes, e.g., 10 minutes, successive executions run almost instantly! That leads me to think that the bottleneck is the query optimizer itself... But, is that even possible? The server runs "Oracle9i Release 9.2.0.1.0 - 64bit Production"; I heard the DBA mention something about "cluster" but that's all I know. Any idea of what to look next? -- --http://alvaro.es- Álvaro G. Vicario - Burgos, Spain -- Mi sitio sobre programación web:http://borrame.com -- Mi web de humor satinado:http://www.demogracia.com -- |
#4
| |||
| |||
|
|
I maintain a PHP-driven web app that's been deployed for several customers that have a variety of Oracle environments. One of them has reported that one of the modules is not working and I've traced back the issue to a very specific SQL query. The query itself does not use a complicate syntax; it's only a bunch of table joins: SELECT DISTINCT regular_table.regular_table_id AS c0, * * * * additional_table_1.foo AS c1, * * * * additional_table_2.bar AS c2, * * * * TO_CHAR(regular_table.start_date, 'DD/MM/YYYY') AS c3, * * * * ........ * * * * temporary_table.sort_order AS sort_order_ FROM temporary_table INNER JOIN regular_table ON temporary_table.regular_table_id=regular_table.reg ular_table_id LEFT JOIN additional_table_1 ON regular_table.regular_table_id=additional_table_1. regular_table_id LEFT JOIN additional_table_2 ON regular_table.additional_table_2_id=additional_tab le_2.additional_table_2_id ........ ORDER BY sort_order_; I assume the issue is probably related to having an insane amount of table joins. I'm testing from SQL*Plus with an empty "temporary_table" table so no rows should be returned. When I run a simplified version of the query the result comes out immediately: SELECT DISTINCT regular_table.regular_table_id AS c0, * * * * additional_table_1.foo AS c1, * * * * TO_CHAR(regular_table.start_date, 'DD/MM/YYYY') AS C3, * * * * temporary_table.sort_order AS sort_order_ FROM temporary_table INNER JOIN regular_table ON temporary_table.regular_table_id=regular_table.reg ular_table_id LEFT JOIN additional_table_1 ON regular_table.regular_table_id=additional_table_1. regular_table_id ORDER BY sort_order_; As I add additional LEFT JOIN clauses one by one, the execution time increase exponentially. Once I manage to successfully run a query that takes, e.g., 10 minutes, successive executions run almost instantly! That leads me to think that the bottleneck is the query optimizer itself... But, is that even possible? The server runs "Oracle9i Release 9.2.0.1.0 - 64bit Production"; I heard the DBA mention something about "cluster" but that's all I know. Any idea of what to look next? -- --http://alvaro.es- Álvaro G. Vicario - Burgos, Spain -- Mi sitio sobre programación web:http://borrame.com -- Mi web de humor satinado:http://www.demogracia.com -- |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
As I add additional LEFT JOIN clauses one by one, the execution time increase exponentially. Once I manage to successfully run a query that takes, e.g., 10 minutes, successive executions run almost instantly! That leads me to think that the bottleneck is the query optimizer itself... But, is that even possible? |
#7
| |||
| |||
|
|
Any idea of what to look next? Query Plans? |

|
"Oracle9i Release 9.2.0.1.0 - 64bit Production"; I heard the DBA mention..." 9.2.0.1? Get this supposed DBA fired right now. |
#8
| |||
| |||
|
|
El 13/05/2011 18:09, joel garry escribió/wrote: On May 13, 4:49 am, "Álvaro G. Vicario" alvaro.NOSPAMTH... (AT) demogracia (DOT) com.invalid> wrote: MOS Bug 4169306: ANSI JOIN GIVES BAD PLAN COMPARED TO ORACLE JOIN WORKAROUND: ----------- Don't use ansi joins. I'm sure that's not the only one, start googling... |
#9
| |||
| |||
|
|
El 18/05/2011 17:40, "Álvaro G. Vicario" escribió/wrote: *> El 13/05/2011 18:09, joel garry escribió/wrote: *>> On May 13, 4:49 am, "Álvaro G. Vicario"*>> <alvaro.NOSPAMTH... (AT) demogracia (DOT) com.invalid> wrote: * *>> MOS Bug 4169306: ANSI JOIN GIVES BAD PLAN COMPARED TO ORACLE JOIN * *>> WORKAROUND: *>> ----------- *>> Don't use ansi joins. * *>> I'm sure that's not the only one, start googling... Good point. Natural joins were introduced in Oracle 9 and Tom hates them. I've made a simple test (ansi vs oracle) and both execution plans have absolutely nothing in common. Curiously, the second one does not display figures (rows, bytes and cost are empty... :-?) From my test, it looks like the ANSI join does not use a single index: it's all TABLE ACCESS FULL :-! -- --http://alvaro.es- Álvaro G. Vicario - Burgos, Spain -- Mi sitio sobre programación web:http://borrame.com -- Mi web de humor satinado:http://www.demogracia.com -- |
#10
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
|
|
On May 18, 9:49 am, "Álvaro G. Vicario" alvaro.NOSPAMTH... (AT) demogracia (DOT) com.invalid> wrote: El 18/05/2011 17:40, "Álvaro G. Vicario" escribió/wrote: El 13/05/2011 18:09, joel garry escribió/wrote: On May 13, 4:49 am, "Álvaro G. Vicario">> <alvaro.NOSPAMTH... (AT) demogracia (DOT) com.invalid> wrote: MOS Bug 4169306: ANSI JOIN GIVES BAD PLAN COMPARED TO ORACLE JOIN WORKAROUND: ----------- Don't use ansi joins. I'm sure that's not the only one, start googling... Good point. Natural joins were introduced in Oracle 9 and Tom hates them. I've made a simple test (ansi vs oracle) and both execution plans have absolutely nothing in common. Curiously, the second one does not display figures (rows, bytes and cost are empty... :-?) From my test, it looks like the ANSI join does not use a single index: it's all TABLE ACCESS FULL :-! How are you getting the explain plan? From the 9.2 docs: "The NULL in the Rows column indicates that the optimizer does not have any statistics on the table." Very odd if you are looking at the same table. If what Mark suggested doesn't do the trick, you may have to 10053 trace. I agree with Carlos, by the way. No one should be running unpatched v. 9 Oracle. |
|
Id | Operation | Name | Rows | Bytes Cost (%CPU)| Time | |
|
0 | SELECT STATEMENT | | 1 | 67 10 (30)| 00:00:01 | |
|
1 | SORT UNIQUE | | 1 | 67 9 (23)| 00:00:01 | |
|
2 | NESTED LOOPS OUTER | | 1 | 67 8 (13)| 00:00:01 | |
|
* 3 | HASH JOIN OUTER | | 1 | 48 7 (15)| 00:00:01 | |
|
4 | NESTED LOOPS | | 1 | 44 3 (0)| 00:00:01 | |
|
5 | TABLE ACCESS FULL | TMP_EDIFICIOS | 1 | 26 2 (0)| 00:00:01 | |
|
6 | TABLE ACCESS BY INDEX ROWID| EDIFICIOS | 1 | 18 1 (0)| 00:00:01 | |
|
* 7 | INDEX UNIQUE SCAN | EDIFICIOS_PK | 1 | 0 (0)| 00:00:01 | |
|
8 | TABLE ACCESS FULL | IMPORTACION | 1 | 4 3 (0)| 00:00:01 | |
|
9 | TABLE ACCESS BY INDEX ROWID | PARCELAS | 1 | 19 1 (0)| 00:00:01 | |
|
* 10 | INDEX UNIQUE SCAN | PARCELAS_PK | 1 | 0 (0)| 00:00:01 | |
|
Id | Operation | Name | Rows | Bytes TempSpc| Cost | |
|
0 | SELECT STATEMENT | | 98M| 6546M| 3382K| 1 | SORT UNIQUE | | 98M| 6546M| 14G| 1692K| |
|
* 2 | HASH JOIN OUTER | | 98M| 6546M| 137M| 2874 | |
|
3 | VIEW | | 2401K| 109M| 677 | * 4 | HASH JOIN OUTER | | 2401K| 169M| 40M| 677 | |
|
5 | VIEW | | 587K| 34M| 24 | * 6 | HASH JOIN | | 587K| 34M| 24 | 7 | TABLE ACCESS FULL| TMP_EDIFICIOS | 8168 | 207K| 10 | 8 | TABLE ACCESS FULL| EDIFICIOS | 7188 | 245K| 9 | 9 | TABLE ACCESS FULL | IMPORTACION | 409 | 5317 | 1 | 10 | TABLE ACCESS FULL | PARCELAS | 4084 | 89848 | 5 | |
|
Id | Operation | Name | Rows | Bytes | Cost | |
|
0 | SELECT STATEMENT | | | | 1 | SORT UNIQUE | | | | 2 | NESTED LOOPS | | | | 3 | NESTED LOOPS | | | | 4 | NESTED LOOPS | | | | 5 | TABLE ACCESS FULL | IMPORTACION | | | 6 | TABLE ACCESS BY INDEX ROWID| EDIFICIOS | | | * 7 | INDEX UNIQUE SCAN | EDIFICIOS_PK | | | 8 | TABLE ACCESS BY INDEX ROWID | PARCELAS | | | * 9 | INDEX UNIQUE SCAN | PARCELAS_PK | | | 10 | TABLE ACCESS BY INDEX ROWID | TMP_EDIFICIOS | | | * 11 | INDEX UNIQUE SCAN | TMP_EDIFICIOS_PK | | | |
|
Id | Operation | Name | Rows | Bytes TempSpc| Cost | |
|
0 | SELECT STATEMENT | | 98M| 6546M| 2874 | * 1 | HASH JOIN OUTER | | 98M| 6546M| 137M| 2874 | |
|
2 | VIEW | | 2401K| 109M| 677 | * 3 | HASH JOIN OUTER | | 2401K| 169M| 40M| 677 | |
|
4 | VIEW | | 587K| 34M| 24 | * 5 | HASH JOIN | | 587K| 34M| 24 | 6 | TABLE ACCESS FULL| TMP_EDIFICIOS | 8168 | 207K| 10 | 7 | TABLE ACCESS FULL| EDIFICIOS | 7188 | 245K| 9 | 8 | TABLE ACCESS FULL | IMPORTACION | 409 | 5317 | 1 | 9 | TABLE ACCESS FULL | PARCELAS | 4084 | 89848 | 5 | |
![]() |
| Thread Tools | |
| Display Modes | |
| |