云原生数据仓库AnalyticDB PostgreSQL版子查询sql使用ORCA优化器无法排序;Legacy排序不准确怎么解决?-- 使用ORCA优化器
--set optimizer = on;
-- 使用Legacy优化器
--set optimizer = off;
-- / 观察kr_date字段排序不正确 /
SELECT pt.*
FROM (
SELECT kr_date, brand, customer_id, customer_name
, vin7, advisor_name, dealer_name, dealer_id, big_region_name_en AS region_code
, campaign_type AS campaignType, dealership_id AS dealerId
FROM ads_dmo.ads_rpt_voc_kr_detail_dmo_t
WHERE kr_date BETWEEN '2024-01-01' AND '2024-01-19'
AND campaign_type = '售后'
ORDER BY kr_date DESC
) pt
LIMIT 50 offset 50
limit 50 offset 50 order by desc 并不会作用在外面的seletc p 查询
SELECT pt.
FROM (
SELECT kr_date, brand, customer_id, customer_name
, vin7, advisor_name, dealer_name, dealer_id, big_region_name_en AS region_code
, campaign_type AS campaignType, dealership_id AS dealerId
FROM ads_dmo.ads_rpt_voc_kr_detail_dmo_t
WHERE kr_date BETWEEN '2024-01-01' AND '2024-01-19'
AND campaign_type = '售后'
) pt ORDER BY pt.kr_date DESC
LIMIT 50 offset 50; ,此回答整理自钉群“云原生数据仓库AnalyticDB PostgreSQL版交流群开源讨论群”
在云原生数据仓库AnalyticDB PostgreSQL版中,使用ORCA优化器时,可能会出现排序不准确的情况。这是因为ORCA优化器在处理子查询时,可能会对排序进行重新排序或调整。
为了解决这个问题,您可以尝试以下方法:
--set optimizer = off;
SELECT pt.*
FROM (
SELECT kr_date, brand, customer_id, customer_name
, vin7, advisor_name, dealer_name, dealer_id, big_region_name_en AS region_code
, campaign_type AS campaignType, dealership_id AS dealerId
FROM ads_dmo.ads_rpt_voc_kr_detail_dmo_t
WHERE kr_date BETWEEN '2024-01-01' AND '2024-01-19'
AND campaign_type = '售后'
ORDER BY kr_date DESC
) pt
LIMIT 50 offset 50
--set optimizer = on;
SELECT pt.*
FROM (
SELECT kr_date, brand, customer_id, customer_name
, vin7, advisor_name, dealer_name, dealer_id, big_region_name_en AS region_code
, campaign_type AS campaignType, dealership_id AS dealerId
FROM ads_dmo.ads_rpt_voc_kr_detail_dmo_t
WHERE kr_date BETWEEN '2024-01-01' AND '2024-01-19'
AND campaign_type = '售后'
ORDER BY kr_date DESC
) pt
LIMIT 50 offset 50
总的来说,在使用ORCA优化器时,需要注意其对排序的影响。如果发现排序不准确,可以尝试使用Legacy优化器、KEYSET方法或检查数据分布来解决该问题。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
阿里云自主研发的云原生数据仓库,具有高并发读写、低峰谷读写、弹性扩展、安全可靠等特性,可支持PB级别数据存储,可广泛应用于BI、机器学习、实时分析、数据挖掘等场景。包含AnalyticDB MySQL版、AnalyticDB PostgreSQL 版。