Subject | Long query help |
---|---|
Author | Rick Debay |
Post date | 2005-11-15T16:23:49Z |
I need to determine what rows match on two columns within a table.
The two columns have non-unique indexes. The query I'm using is:
Select
*
From
tbl t1
Where
exists (
select 1
from tbl t2
where (t2.a = t1.b and t2.a is not null and t1.b is not null)
or (t2.b = t1.a and t2.b is not null and t1.a is not null)
)
The table has 120,045 rows and the query is taking hours. The plan is:
PLAN (T1 NATURAL)
PLAN (T2 INDEX (I_TBL_A,I_TBL_B))
The duplicates are all null values, there are only a dozen or so
non-null duplicates
Index I_TBL_B (1)
Depth: 2, leaf buckets: 189, nodes: 120045
Average data length: 0.00, total dup: 98543, max dup: 98498
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 171
60 - 79% = 13
80 - 99% = 5
Index I_TBL_A (2)
Depth: 2, leaf buckets: 252, nodes: 120045
Average data length: 4.00, total dup: 17384, max dup: 17371
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 178
60 - 79% = 51
80 - 99% = 23
The only change I could come up with would be to append the primary key
to the index, but I doubt it would help (and I can't interrupt the query
to test it).
The two columns have non-unique indexes. The query I'm using is:
Select
*
From
tbl t1
Where
exists (
select 1
from tbl t2
where (t2.a = t1.b and t2.a is not null and t1.b is not null)
or (t2.b = t1.a and t2.b is not null and t1.a is not null)
)
The table has 120,045 rows and the query is taking hours. The plan is:
PLAN (T1 NATURAL)
PLAN (T2 INDEX (I_TBL_A,I_TBL_B))
The duplicates are all null values, there are only a dozen or so
non-null duplicates
Index I_TBL_B (1)
Depth: 2, leaf buckets: 189, nodes: 120045
Average data length: 0.00, total dup: 98543, max dup: 98498
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 171
60 - 79% = 13
80 - 99% = 5
Index I_TBL_A (2)
Depth: 2, leaf buckets: 252, nodes: 120045
Average data length: 4.00, total dup: 17384, max dup: 17371
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 178
60 - 79% = 51
80 - 99% = 23
The only change I could come up with would be to append the primary key
to the index, but I doubt it would help (and I can't interrupt the query
to test it).