Skip to content
Advertisement

VIEW – INDEX SQL SERVEr

Does anyone know another way to run the query below more efficiently? I’m using SQL Server 2014. I’m facing a problem if i create index on table or on view .

On table 2 (TB_FATURA_ITEM_TRANSACAO_HST) , has stored 50 million rows .

I was wondering using Schemabiding on View , but I was looking in some articles that is not recommended when you are using UNION .

Probably I got see which indexes I will use on it, right ?

…………………………………………………………

I applied the query that Gordon posted, I got huge performance on it. I reduced 15 minutes to 5 minutes. Anyway I got hustle on it to reduce more time.

Advertisement

Answer

The overhead in the view is due to duplication elimination. So, the first suggestion is to use union all, if there are no duplicates between the two tables. If you can, problem solved.

If not, you can use not exists. I might speculate that something like this would work:

This where clause in the subquery would contain all columns that need to be equal for a row to be considered a duplicate. I am speculating the id is sufficient.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement