2017-07-21 63 views

回答

1

書面,沒有索引會幫助,因爲你必須在同一行(當然,也有索引類型,但它們不會是微不足道的實施中兩列在SQL Server中)。如果你沒有很多記錄匹配的情況下,你可以創建一個計算列和索引:

create table resources (
    id bigint primary key, 
    value nvarchar(255), 
    updateId bigint, 
    pushUpdateId bigint, 
    compare_updateId_pushUpdateId as (case when updateId > pushUpdateId then 1 else 0 end) 
); 

然後,您可以創建一個索引:

create index idx_resources_2 on resources(compare_updateId_pushUpdateId, id); 

然後短語查詢爲:

select id 
from resources 
where compare_updateId_pushUpdateId = 1; 
+0

@JeroenMostert。 。 。謝謝。 –

相關問題