Time sucking queries
Had a user submit a query recently:
select count(*) from (select * from viewA UNION select * from viewB)
viewA pulls from two tables with a combined 1.5 billion rows and around 60 columns. viewB pulls from a table with about 300 million rows. I rewrote the query as follows:
select (select count(*) from viewA) + (select count(*) from viewB) AS count
Same result but the first query has an explain plan with a cost 26X the second. Second query runs in about 3 minutes.
select count(*) from (select * from viewA UNION select * from viewB)
viewA pulls from two tables with a combined 1.5 billion rows and around 60 columns. viewB pulls from a table with about 300 million rows. I rewrote the query as follows:
select (select count(*) from viewA) + (select count(*) from viewB) AS count
Same result but the first query has an explain plan with a cost 26X the second. Second query runs in about 3 minutes.
Comments
Post a Comment