Asad Iqbal
Asad Iqbal

Reputation: 304

SQL Performance Results

if we get data from code through sql using select query and same query is executed on sql view, then which way is faster from performance point. mean view's display data faster or direct sql query that we run on tables fetch the data faster?

Upvotes: 0

Views: 73

Answers (3)

HLGEM
HLGEM

Reputation: 96570

Lots of factors could affect this. Is the view an indexed view? It could be faster. Is the view a view that calls other views that calls other views? It will probably be significantly slower than directly hitting that tables (especially if the view chain is long and complicated). In looking at performance, the particular query and the particular hardware set-up will dictate which is faster. You need to try both ways to see.

Upvotes: 0

atrain
atrain

Reputation: 9255

Neither is faster. A view is just a stored query, so if they are structured the same they should execute in the same timeframe. If you look at the execution plan for the plain SQL or the view execute, they should be identical if the SQL in both is identical.

Upvotes: 0

ckruse
ckruse

Reputation: 9740

You cannot answer such a generally asked question. Views can be faster, but don't have to be. It highly depends on the DBMS you are using, on the view you created, on the amount of data you have loaded, on the indexes you created and on the queries you run against the table/view.

Upvotes: 1

Related Questions