I have a table for about 100,000 users in it.
First Case:
explain select state, count(*) as cnt from users where state = 'ca'
When I do an explain plan for the above query I get the cost as 5200
Second Case:
Create or replace view vw_users as select state, count(*) as cnt from users
Explain select cnt from vw_users where state = 'ca'
When I do an explain plan on the second query I get the cost as 100,000.
How does the where clause in the view work? Is the where clause applied after the view retrieves all the rows? How do I fix this issue?