tags:

views:

70

answers:

3

Hi, I have a three tables in an application and I need to perform a query which joins all three of them on a regular basis. Chances are that all three of these tables will be updated often.

I'm considering using a view to avoid having to use the verbose join syntax in several places within my code. Would this be a suitable options? I have not used views in a large scale application before and am unsure of the effects they will have on performance (positive or negative).

Any advice would be greatly appreciated.

Thanks.

+1  A: 

In MySQL a view is generally executed only when it's requested, so it's almost the same like writing the jong query or executing a query on the view, so in my experience you shouldn't hit any performance problems as long as the join query is fast as well.

Fabian
+1  A: 

MySQL views are relatively new but this in my opinion would be a suitable option. Test your query by prefixing your query with an EXPLAIN.

Jay
A: 

Using a database view to eliminate code replication does not seem like the proper thing to do. You should instead consider refactoring your code.

Doing as suggested would still mean replicating the call to the view several times in your code. Which is bad practice IMHO.

Peter Lindqvist
Sorry, I didn't mean exactly the same, just similar. There will be some variations and I will just use WHERE clauses to filter what I get.
Dan
Oh, then my answer is no use to you, however i'll leave it there anyway.
Peter Lindqvist