SQL: View to Table - is it view queries using table indexes?

I am using the view ("UsersActive") against my table ("Users"). There is only one filter in the view, it checks whether DateTime Users.DeletedOn is NULL; it basically contains all users that are not deleted.

If I now run Linq queries against a view instead of a table, will they still use table indexes or do I need to create special indexes for the view? In my opinion, a view is nothing more than a predefined query, and should work just as if I were directly addressing it:

   SELECT * FROM Users WHERE DeletedON = NULL

Is my assumption that base table indexes will still be used correctly?

+3
source share
5 answers

In most cases, the SQL Server query optimizer is smart enough to use indexes in the base table. You can see this by looking at query plans.

If you have an enterprise version of SQL Server, you can also use indexed views.

+5
source

Views are pretty completely transparent right to the underlying SQL statements. This is a good reliable design assumption.

+2
source

.

, , .

( ) . , .

, - NULL, .

+1

, :

SELECT * FROM WHERE DeletedON IS NULL

DeletedON = NULL , DeletedON IS NULL

0

, , , , . , .

You can also index your view, in which case the data set will be mapped to a physical disk, and you will have two sets of indexes.

-1
source

Source: https://habr.com/ru/post/1709548/


All Articles