Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

审核带有having子句的sql报错 #2867

Open
iwanghc opened this issue Jan 13, 2025 · 0 comments
Open

审核带有having子句的sql报错 #2867

iwanghc opened this issue Jan 13, 2025 · 0 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@iwanghc
Copy link
Collaborator

iwanghc commented Jan 13, 2025

版本信息(Version)

SQLE: v4.2502-pre1

问题描述(Describe)

开启规则“查询数据量超过阈值,筛选条件必须带上主键或者索引”,当审核的sql带有having子句时出现Error 1054 (42S22): Unknown column 'xxxx' in 'having clause'报错

截图或日志(Log)

image

如何复现(To Reproduce)

  1. 数据库中创建表
CREATE TABLE `tb1` (
  `column3` varchar(100) COLLATE utf8mb4_bin DEFAULT NULL,
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `column1` varchar(100) COLLATE utf8mb4_bin DEFAULT NULL,
  `column2` varchar(100) COLLATE utf8mb4_bin DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
  1. 开启规则“查询数据量超过阈值,筛选条件必须带上主键或者索引”
  2. 审核以下sql
   SELECT sum(id) as total_amt FROM tb2 GROUP BY column1 HAVING total_amt <> 0;
  1. 出现报错Error 1054 (42S22): Unknown column 'total_amt' in 'having clause'

问题原因

在获取影响行数的时候,将select语句中的查询字段替换为数字1
(关联issue:https://github.com/actiontech/sqle/issues/2175#issuecomment-1865658820)
导致having子句的字段找不到。

image

解决方案

变更影响面

受影响的模块或功能

外部引用的潜在问题或风险

版本兼容性

测试建议

@iwanghc iwanghc added the bug Something isn't working label Jan 13, 2025
@ColdWaterLW ColdWaterLW added this to the v4.2502.0 milestone Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants