오랜 시간이 걸리는 프로덕션의 쿼리를 최적화하려고합니다. 목표는 일치하는 필드 값 기준에 따라 중복 레코드를 찾은 다음 삭제하는 것입니다. 현재 쿼리는 t1.col1 = t2.col1의 내부 조인을 통한 자체 조인을 사용하고 값을 확인하기위한 where 절을 사용합니다.복제본을 검사 할 때 최상의자가 결합 기술
select * from table t1
inner join table t2 on t1.col1 = t2.col1
where t1.col2 = t2.col2 ...
이 작업을 수행하는 더 좋은 방법은 무엇입니까? 또는 인덱스를 기반으로 모두 동일합니까? 어쩌면
select * from table t1, table t2
where t1.col1 = t2.col1, t2.col2 = t2.col2 ...
이 표에는 100m + 행이 있습니다.
MS SQL, SQL 서버 2008 엔터프라이즈
select distinct t2.id
from table1 t1 with (nolock)
inner join table1 t2 with (nolock) on t1.ckid=t2.ckid
left join table2 t3 on t1.cid = t3.cid and t1.typeid = t3.typeid
where
t2.id > @Max_id and
t2.timestamp > t1.timestamp and
t2.rid = 2 and
isnull(t1.col1,'') = isnull(t2.col1,'') and
isnull(t1.cid,-1) = isnull(t2.cid,-1) and
isnull(t1.rid,-1) = isnull(t2.rid,-1)and
isnull(t1.typeid,-1) = isnull(t2.typeid,-1) and
isnull(t1.cktypeid,-1) = isnull(t2.cktypeid,-1) and
isnull(t1.oid,'') = isnull(t2.oid,'') and
isnull(t1.stypeid,-1) = isnull(t2.stypeid,-1)
and (
(
t3.uniqueoid = 1
)
or
(
t3.uniqueoid is null and
isnull(t1.col1,'') = isnull(t2.col1,'') and
isnull(t1.col2,'') = isnull(t2.col2,'') and
isnull(t1.rdid,-1) = isnull(t2.rdid,-1) and
isnull(t1.stid,-1) = isnull(t2.stid,-1) and
isnull(t1.huaid,-1) = isnull(t2.huaid,-1) and
isnull(t1.lpid,-1) = isnull(t2.lpid,-1) and
isnull(t1.col3,-1) = isnull(t2.col3,-1)
)
)
MS SQL? 그렇다면 SQL Server의 버전은 무엇입니까? –
@Bruno 죄송합니다. 질문과 태그를 업데이트했습니다. –
@Mitch 아니오 동일한 테이블에 가입하는 하나의 테이블입니다. 자체 가입이 아닌 방법은 무엇입니까? –