已关闭
[Bug]: 建联合索引索引列指定DESC NULLS LAST,查询无法走索引【YMJ】 #8331
zhangxubo创建于  7月18日关闭于  14 天前
zhangxubo
zhangxubo成员
7月18日 创建

测试类型

SQL功能

测试版本

7.0.0LTS

问题描述

建联合索引索引列指定DESC NULLS LAST,查询无法走索引

操作系统和硬件信息

all

测试环境

企业版单机

被测功能

预置条件

操作步骤

  1. 建表,指定复合索引列 desc nulls last
create table test2(id int,name varchar);
create index test2_idx on test2(id, name desc nulls last);
  1. 插入数据
CREATE OR REPLACE PROCEDURE func_batch_insert2()
AS  
BEGIN  
       FOR I IN 1..100000 LOOP  
		insert into test2 values(I, 'name' || I);
       END LOOP; 
END;
/

call func_batch_insert2();

查询条件order by 带上两个列,发现不走索引

select * from test2 order by id,name desc limit 20;

image.png

预期输出

可以走索引

实际输出

未走索引

日志信息

其他说明:

  1. 如果建表的索引不带 desc nulls last 则可以正常走索引
    image.png

  2. 建表索引带 desc nulls last ,PG是可以走索引的。

create table test2(id int,name varchar);
create index test2_idx on test2(id, name desc nulls last);

CREATE OR REPLACE PROCEDURE func_batch_insert2()
LANGUAGE plpgsql
AS $$
DECLARE
    i INT;
BEGIN
    FOR i IN 1..100000 LOOP
        INSERT INTO test2 VALUES(i, 'name' || i);
    END LOOP;
    COMMIT;
END;
$$;

CALL func_batch_insert2();

image.png

提单组织

一线客户

测试代码

likedislike
zhangxubozhangxubo成员
7月18日 添加了label:bug
opengauss_bot
opengauss_bot成员
7月18日 评论:

This issue requires an assignee. Since you haven't specified one, we've assigned TestManager as the default assignee for this issue.

likedislike
opengauss_botopengauss_bot成员
7月18日 将 TestManager 设为负责人
opengauss_botopengauss_bot成员
7月18日 添加了label:sig/StorageEngine,sig/AI,sig/CM,sig/CloudNative,sig/SecurityTechnology,sig/SQLEngine
opengauss_bot
opengauss_bot成员
7月18日 评论:

Welcome To openGauss Community

Hey @zhangxubo , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.

Contact Guide

If you have any questions, please contact the SIG: StorageEngine, AI, CM, CloudNative, SecurityTechnology, SQLEngine ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @Igali, @bihua111, @cailei19, @h_ray, @levy53071, @libiao2024, @lihaixiao, @mrzack, @wangfeihuo, @wuyuechuan, @xiong_xjun, @zhangfengzhi123, @zhangxubo, @zhangzq131, @zjh_hw .

likedislike
zhangxubozhangxubo成员
7月18日 修改了issue 的描述
zhangxubozhangxubo成员
7月18日 关联了看板:openGauss 7.0.0-LTS
ywzq1161327784ywzq1161327784成员
7月27日 将 wofanzheng 设为负责人
ywzq1161327784ywzq1161327784成员
7月27日 移除了负责人 TestManager
wofanzhengwofanzheng成员
7月31日 关联了pull request:修复联合索引排序无法利用索引前缀问题
wofanzhengwofanzheng成员
22 天前 关联了pull request:[7.0.0] 修复联合索引排序无法利用索引前缀问题
wofanzhengwofanzheng成员
21 天前 issue状态由 待办的 改变为 已完成
wofanzheng
wofanzheng成员
17 天前 评论:

自验证通过:
image.png

likedislike
wofanzhengwofanzheng成员
17 天前 issue状态由 已完成 改变为 待回归
yangl_
yangl_成员
14 天前 评论:

回归日期:2026.09.15
回归结论:通过
回归过程:
image.png

likedislike
yangl_yangl_成员
14 天前 issue状态由 待回归 改变为 已验收
yangl_yangl_成员
14 天前 关闭了 issue