각 테이블의 idx:자동증가 인덱스 stime: 저장시간, jdate:작업일자
입니다.
select idx,stime,jdate,물품,물품코드,단가,현재상태
from( select idx,stime,jdate,물품,물품코드,단가,\'I\'as 현재상태
from t_입고 where jdate<=:요청일자
union select idx,stime,jdate,물품,물품코드,단가,\'O\'as 현재상태
from t_출고 where jdate<=:요청일자
union select idx,stime,jdate,물품,물품코드,단가,\'B\'as 현재상태
from t_반입 where jdate<=:요청일자
union select idx,stime,jdate,물품,물품코드,단가,\'P\'as 현재상태
from t_반품 where jdate<=:요청일자
union select idx,stime,jdate,물품,물품코드,단가,\'S\'as 현재상태
from t_판매 where jdate<=:요청일자
)a where a.stime=(select max(stime) from(
select stime from t_입고 where
jdate<=:요청일자
union select stime from t_출고 where
jdate<=:요청일자
union select stime from t_반입 where
jdate<=:요청일자
union select stime from t_반품 where
jdate<=:요청일자
union select stime from t_판매 where
jdate<=:요청일자)b
where a.물품코드=b.물품코드 and a.현재상태 in
(\'I\',\'O\',\'B\')
order by a.물품,a.stime
구문은 이런형식인데,
같은구문으로 Ms-SQL과 PostgreSQL으로 테스트한결과,
Ms-SQL은 5초도 안걸리는 반면, PostgreSQL은 2분도 더
걸립니다.
더 이해가 안가는건, 자료양이 같은 매장에서 Ms-SQL은 6개월분,
PostgreSQL은 겨우 3일분입니다.
Ms-SQL이 수백배 더 많다는 거죠.
PostgreSQL이 union이 늦어서 그런건가요?
좀 빠른 검색을 할려면 어떻게 해야죠?
|