Home » RDBMS Server » Performance Tuning » Query performance decreased between order by ASC/DESC
Query performance decreased between order by ASC/DESC [message #532962] |
Fri, 25 November 2011 11:33 |
|
euphORIA
Messages: 3 Registered: November 2011
|
Junior Member |
|
|
Hello all,
I am having difficulties trying to fix the performance issue I am having running one query, which runs fine (3 seconds) if no order or an ASC order is applied to the PK field of the main table, but it is very slow when the order by is DESC.
The query would look like:
SELECT A.FIELD_A,
A.FIELD_A,
A.FIELD_A,
A.FIELD_A,
A.FIELD_A,
A.FIELD_A,
B.FIELD_B,
C.FIELD_B,
D.FIELD_B,
E.FIELD_B,
...
L.FIELD_B,
L.FIELD_C
FROM HAT_TABLE_A A
LEFT JOIN TABLE_B B
ON A.FIELD_A=B.FIELD_A
LEFT JOIN TABLE_C C
ON A.FIELD_A=C.FIELD_A
LEFT JOIN TABLE_D D
ON A.FIELD_A=D.FIELD_A
LEFT JOIN TABLE_D D
ON A.FIELD_A=D.FIELD_A
LEFT JOIN TABLE_E E
ON A.FIELD_A=E.FIELD_A
...
LEFT JOIN TABLE_L L
ON A.FIELD_A=L.FIELD_A
order by A.FIELD_A DESC
In total, there are 12 tables, the main one (TABLE_A) and all the others that are linked to main one, and which in my test are a one to one relationship to TABLE_A (In the future, this will change), except table L that contains 20 times more data.
Basically, tables A to K have 50K rows, and table L has 1 million.
FIELD_A is the primary key for TABLE_A, and is used as foreign key for all other tables. I have tried creating an index on [TABLE_A.FIELD_A DESC] but it does not change anything. All stats are up to date.
Do you know what could be the reason why changing the order by from ASC to DESC may decrease the performance that much?
|
|
|
|
|
Re: Query performance decreased between order by ASC/DESC [message #533089 is a reply to message #532977] |
Mon, 28 November 2011 04:11 |
|
euphORIA
Messages: 3 Registered: November 2011
|
Junior Member |
|
|
The explain plan is different, depending on the order (I am only including the last lines, all the rest is the same in both plans):
ASC order - Cost: 10,408 for the sorting:
SELECT STATEMENT ALL_ROWSCost: 10,408 Bytes: 23,007,600 Cardinality: 63,910
57 SORT UNIQUE Cost: 10,408 Bytes: 23,007,600 Cardinality: 63,910
56 SORT GROUP BY Cost: 10,408 Bytes: 23,007,600 Cardinality: 63,910
55 HASH JOIN RIGHT OUTER Cost: 5,499 Bytes: 23,007,600 Cardinality: 63,910
...
DESC order - Cost: 15,316 for the sorting:
SELECT STATEMENT ALL_ROWSCost: [color=red]15,316[/color] Bytes: 23,007,600 Cardinality: 63,910
57 SORT UNIQUE Cost: [color=red]15,316[/color] Bytes: 23,007,600 Cardinality: 63,910
56 SORT GROUP BY Cost: [color=red]15,316[/color] Bytes: 23,007,600 Cardinality: 63,910
55 HASH JOIN RIGHT OUTER Cost: 5,499 Bytes: 23,007,600 Cardinality: 63,910
...
Does it help? Unfortunately I have no access to trace files.
In general, is there any recommendation to follow when sorting a query in DESC order? this is the first time that I am facing a similar problem with the performance just for changing the order by
[Updated on: Mon, 28 November 2011 04:13] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Sun Nov 24 13:04:48 CST 2024
|