0
DB2에서이 쿼리를 최적화하려고합니다. url 키워드를 선택하는 내부 쿼리는 쿼리를 15 초에서 10 분 정도 걸립니다. 나는 문제를 추적 해 봤는데 비교 'where urlkeyword = c.catentry_id'가 varchar 필드 (url 키워드)를 bigint 필드와 비교하기 때문인 것으로 보인다. varachar를 문자열 값과 비교하기 위해 그것을 수정하면 훨씬 더 빠르게 진행됩니다. 내 질문 :최적화 쿼리 - bigint에서 varchar/char로 캐스팅하는 방법?
bigint에서 varchar로 c.catentry_id를 캐스팅하는 구문은 무엇입니까?
select
xmlelement(NAME "Products",xmlagg(xmlrow(c.field5 as "ExternalId",
cd.name as "Name",
cg.identifier as "CategoryExternalId",
concat('@[email protected]', cd.thumbnail) as "ImageUrl",
(select urlkeyword from seourl s
inner join seourlkeyword sk
on s.seourl_id = sk.seourl_id
where urlkeyword = c.catentry_id
) as "ProductPageUrl",
mfpartnumber as "ManufacturerPartNumber",
cd.shortdescription as "Description",
c.field1 as "BrandExternalId" option row "Product"))) as xml_document
from catentry c
inner join catentdesc cd
on c.catentry_id = cd.catentry_id and cd.language_id = -1
inner join catgpenrel cgp
on c.catentry_id = cgp.catentry_id
inner join catgroup cg
on cg.catgroup_id = cgp.catgroup_id
where cgp.catalog_id in
(select catalog_id from catalog where identifier = 'Web_OW Default Web')
나는 char에 캐스트했지만 고마워. 테이블은 인덱싱되지만 인덱스 스캔은 어떤 이유로 든 오른쪽을 변환하는 대신 왼쪽면 (문자열을 숫자로 변환)으로 변환합니다. 그래서 오른쪽 주조가 동작을 강제합니다. 이 작동, 쿼리는 지금 다시 15 초 ... –