Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Choice of index

$
0
0
I have a table with three fields, let's call them username, eventDate and eventType. I have millions of rows of data in it, and I have two indices created for this table already: idx_event which indexes username and eventDate together, and idx_type which only indexes the eventType field. Both indexes support reverse lookup.

I want to run queries that all look like this:

SELECT username, eventDate
FROM myTable
WHERE eventType IN (....)
GROUP BY username, eventDate

The only part that changes from query to query, is the IN part.

I wanted to optimize my query so I ran EXPLAIN for one such query, and here is what I found in my SYSTOOLS.EXPLAIN_OPERATOR table:

Code:

OPERATOR_ID        OPERATOR_TYPE        TOTAL_COST        IO_COST                CPU_COST        FIRST_ROW_COST
1                RETURN                635.29                84                1022526.94        635.29
2                GRPBY                635.29                84                1022526.94        635.29
3                TBSCAN                635.29                84                1017026.94        635.29
4                SORT                  635.29                84                1010239.94        635.29
5                NLJOIN                635.28                84                981343.19        30.26
6                TBSCAN                0.00                0                720.00                0.00
7                FETCH                30.26                4                92573.96        30.26
8                IXSCAN                22.70                3                80753.96        22.70

If I understand this correctly, it reads from bottom to top; first an index (I think it is the idx_type) is used to fetch the reslut of where part, but then there is a join (I think it is the IN part), and then a SORT and GRPBY which is for the GROUP BY.

Assuming I got it right, it seems that the rate limiting factor is the NLJOIN part. How can I used indices to make it more efficient?

Viewing all articles
Browse latest Browse all 13329

Trending Articles