已关闭
[Bug]: B库下创建分区键带函数表达式to_days,导出导入后报错:The Partition Expr can't be 910 type【DH】 #8359
zhangxubo创建于  7月28日关闭于  17 天前
zhangxubo
zhangxubo成员
7月28日 创建

测试类型

SQL功能

测试版本

6.0.0

问题描述

B库下创建分区键带函数表达式to_days,导出导入后报错:The Partition Expr can't be 910 type

之前 yearweek 函数在作为分区键表达式也有该问题,单独有解决过。

https://gitcode.com/opengauss/openGauss-server/issues/7895

https://gitcode.com/opengauss/Plugin/pull/2362

操作系统和硬件信息

all

测试环境

企业版单机

被测功能

B库导出导入

预置条件

操作步骤

  1. 建表
create table test_todays(
"CAP_DAY" date
)
PARTITION BY RANGE (to_days(("CAP_DAY")))
( 
    PARTITION p202210 VALUES LESS THAN (738825),
    PARTITION p202211 VALUES LESS THAN (738855)
);
  1. gs_dump导出然后gsql导入报错

其实建表后,可以看到表定义多了timestamp without time zone类型。导出时候获取的这里面表定义,在使用这个表定义创建就报错了。

CREATE TABLE test_todays2 (                                            
     "CAP_DAY" date                                                    
 )                                                                     
 WITH (orientation=row, compression=no)                                
 PARTITION BY RANGE (to_days(("CAP_DAY")::timestamp without time zone))
 (                                                                     
     PARTITION p202210 VALUES LESS THAN (738825),                      
     PARTITION p202211 VALUES LESS THAN (738855)                       
 )                                                                     
 ENABLE ROW MOVEMENT;

image.png

image.png

预期输出

创建成功。

B库支持分区键表达式的函数有很多:
https://docs.opengauss.org/zh/docs/latest/extension_reference/dolphin-CREATE-TABLE-PARTITION.html

只支持部分函数允许在分区键中使用,支持的函数为: ABS()、CEILING()、DATEDIFF()、DAY()、DAYOFMONTH()、DAYOFWEEK()、DAYOFYEAR()、EXTRACT() 、FLOOR()、HOUR()、MICROSECOND()、MINUTE()、MOD()、MONTH()、QUARTER()、SECOND()、TIME_TO_SEC()、TO_DAYS()、TO_SECONDS()、UNIX_TIMESTAMP()、WEEKDAY()、YEAR()、YEARWEEK()。

但不是所有都是有问题。 能否改为通用的方案( 上述pr针对每个函数要单独适配。)

实际输出

创建失败

日志信息

见截图

提单组织

一线客户

测试代码

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

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月28日 将 TestManager 设为负责人
opengauss_botopengauss_bot成员
7月28日 添加了label:sig/StorageEngine,sig/AI,sig/CM,sig/CloudNative,sig/SecurityTechnology,sig/SQLEngine
opengauss_bot
opengauss_bot成员
7月28日 评论:

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月28日 将 ywzq1161327784 设为负责人
此处折叠了7条事件消息 查看更多
wofanzhengwofanzheng成员
20 天前 关联了pull request:【回合6.0.0】同步修复分区函数表达式带类型转换导入失败
wofanzheng
wofanzheng成员
20 天前 评论:

自验证OK:

DROP DATABASE IF EXISTS issue8359_b;
CREATE DATABASE issue8359_b DBCOMPATIBILITY 'B';
\c issue8359_b

CREATE EXTENSION IF NOT EXISTS dolphin;
SET dolphin.sql_mode =
    'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,pad_char_to_full_length';

-- 1. The original DDL from the issue succeeds.
CREATE TABLE test_todays (
    "CAP_DAY" date
)
PARTITION BY RANGE (to_days(("CAP_DAY")))
(
    PARTITION p202210 VALUES LESS THAN (738825),
    PARTITION p202211 VALUES LESS THAN (738855)
);

CREATE TABLE test_todays2 (                                            
     "CAP_DAY" date                                                    
 )                                                                     
 WITH (orientation=row, compression=no)                                
 PARTITION BY RANGE (to_days(("CAP_DAY")::timestamp without time zone))
 (                                                                     
     PARTITION p202210 VALUES LESS THAN (738825),                      
     PARTITION p202211 VALUES LESS THAN (738855)                       
 )                                                                     
 ENABLE ROW MOVEMENT;

image.png

likedislike
wofanzhengwofanzheng成员
20 天前 issue状态由 已完成 改变为 待回归
wofanzheng
wofanzheng成员
19 天前 评论:

【6.0.6 B004】自验证OK
image.png

likedislike
wuchenlong
wuchenlong成员
18 天前 评论:

回归版本:6.0.6 B004(openGauss 6.0.6 build abb18fca,compiled at 2026-08-27 10:04:18)
回归环境:224 本机三节点集群(ARM),cluster_state=Normal,B 兼容库 issue8359_b / issue8359_b2
结论:通过(to_days 分区建表、dump 形态 DDL、gs_dump→gsql 导入均成功)

完整回归 SQL

SELECT version();
DROP DATABASE IF EXISTS issue8359_b;
CREATE DATABASE issue8359_b DBCOMPATIBILITY 'B';
\c issue8359_b
CREATE EXTENSION IF NOT EXISTS dolphin;
SET dolphin.sql_mode =
    'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,pad_char_to_full_length';

CREATE TABLE test_todays (
    "CAP_DAY" date
)
PARTITION BY RANGE (to_days(("CAP_DAY")))
(
    PARTITION p202210 VALUES LESS THAN (738825),
    PARTITION p202211 VALUES LESS THAN (738855)
);

CREATE TABLE test_todays2 (
     "CAP_DAY" date
 )
 WITH (orientation=row, compression=no)
 PARTITION BY RANGE (to_days(("CAP_DAY")::timestamp without time zone))
 (
     PARTITION p202210 VALUES LESS THAN (738825),
     PARTITION p202211 VALUES LESS THAN (738855)
 )
 ENABLE ROW MOVEMENT;

\d+ test_todays
\d+ test_todays2

-- dump / restore
-- gs_dump -p 15700 -f /tmp/issue8359_todays.sql -t test_todays issue8359_b
DROP DATABASE IF EXISTS issue8359_b2;
CREATE DATABASE issue8359_b2 DBCOMPATIBILITY 'B';
\c issue8359_b2
CREATE EXTENSION IF NOT EXISTS dolphin;
SET dolphin.sql_mode =
    'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,pad_char_to_full_length';
-- gsql -d issue8359_b2 -p 15700 -f /tmp/issue8359_todays.sql
\d+ test_todays

实际输出

CREATE TABLE
CREATE TABLE
Partition By RANGE(to_days(("CAP_DAY")::timestamp without time zone))
...
gs_dump ... dump database issue8359_b successfully
CREATE TABLE
ALTER TABLE
8359_DUMP_RESTORE_PASS
likedislike
wuchenlongwuchenlong成员
17 天前 issue状态由 待回归 改变为 已验收
wuchenlongwuchenlong成员
17 天前 关闭了 issue