MySQL Forums
Forum List  »  Stored Procedures

In general, is direct query faster than a view?
Posted by: Alan Myers
Date: July 15, 2012 02:52PM

Just a general question. I'm wondering if it's CRAZY to build view that groups data when I can just do my own count:

So, for example, a simple count. (There's an index on id):
SELECT count(1) from largeTable where id=100

Is there huge overhead to create a view as:
CREATE VIEW myView AS
SELECT a.id as id, count(b.id) as num
from smallTable a left join largeTable b on (a.id=b.id)
group by a.id

and then pulling data from the view:
SELECT num from myView where id = 100

As long as I don't call the view without a where clause, are they equivalent?

Options: ReplyQuote


Subject
Views
Written By
Posted
In general, is direct query faster than a view?
3328
July 15, 2012 02:52PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.