我试图在DB2中优化此查询。选择url关键字的内部查询将查询从15秒到大约10分钟。我已经跟踪了问题,这似乎是因为比较'其中urlkeyword = c.catentry_id'将varchar字段(urlkeyword)与bigint字段进行比较。如果我修改它以将varachar与字符串值进行比较,它会变得快几个数量级。我的问题是:
将c.catentry_id从bigint转换为varchar的语法是什么? (我想如果我能做到这一点就会解决它)
select
xmlelement(NAME "Products",xmlagg(xmlrow(c.field5 as "ExternalId",
cd.name as "Name",
cg.identifier as "CategoryExternalId",
concat('@bv.base.image.url@', 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')
答案 0 :(得分:0)
你可以试试这个
where urlkeyword = CAST(c.catentry_id AS VARCHAR(n))
显然你需要用urlkeyword字段的长度替换n
。
但我认为问题涉及索引正确的表格。
我希望这会对你有所帮助。