cfstoredproc vs query
What advantage does using
a cfstoredproc which selects from a view
rather than
just selecting from the view in a cfquery have?
What advantage does using
a cfstoredproc which selects from a view
rather than
just selecting from the view in a cfquery have?
Agreed. Making a comparison of a <cfquery> passing an SQL statement and a procedure which simply runs the same SQL is not really a sensible one, but the answer is "very little difference".
The thing with using procs for one's SQL is that one can then block any other arbitrary SQL being run by a client (like a JDBC driver), meaning only procs can be run, meaning all the DB logic is on the DB, and no-one can run spurious queries. So that's the security side of things.
From a functionality point of view, one can perform far more complex logic on the DB using a proc, rather than shipping data base to CF and manipulating it there. Minimising CF's requirement to do data manipulation is desirable because it's not really the best tool for the job: the DB is.
Performance-wise, a proc is precompiled, so there's a slight saving there. Running two different (unparameterised) queries against your view still requires each query to have and execution plan created and then for it to be compiled before it is run. That you're querying a view instead of a table is neither here nor there as far as that goes. Although depending on your DB, using a view still requires the underlying SQL which created the view to be re-executed each time you query it.
--
Adam
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.