【StoneDB研发日志】union功能bug记录

1、问题现象

create database syw_mtr;
use syw_mtr;
CREATE TABLE t1 (f1 VARCHAR(255) CHARACTER SET utf8)engine=tianmu;
CREATE TABLE t2 AS SELECT LEFT(f1,171) AS f2 FROM t1 UNION SELECT LEFT(f1,171) AS f2 FROM t1;
ERROR 2013 (HY000): Lost connection to MySQL server during query

问题issue:https://github.com/stoneatom/stonedb/issues/226

2、问题原因

bug代码行

Query_result_create::prepare (sql_insert.cc:2753)

create_table->table不为空

assert(create_table->table == NULL);

stonedb堆栈

    libc.so.6!raise (未知源:0)
    libc.so.6!abort (未知源:0)
    libc.so.6!__assert_fail_base (未知源:0)
    libc.so.6!__assert_fail (未知源:0)
    Query_result_create::prepare(Query_result_create * const this, List & values, SELECT_LEX_UNIT * u) (\opt\litaihong\stonedb\sql\sql_insert.cc:2753)
    st_select_lex::prepare(st_select_lex * const this, THD * thd) (\opt\litaihong\stonedb\sql\sql_resolver.cc:361)
    st_select_lex_unit::prepare_fake_select_lex(st_select_lex_unit * const this, THD * thd_arg) (\opt\litaihong\stonedb\sql\sql_union.cc:441)
    st_select_lex_unit::optimize_for_stonedb(st_select_lex_unit * const this) (\opt\litaihong\stonedb\storage\stonedb\core\engine_execute.cpp:586)
    stonedb::core::Engine::HandleSelect(stonedb::core::Engine * const this, THD * thd, LEX * lex, Query_result *& result, ulong setup_tables_done_option, int & res, int & optimize_after_sdb, int & sdb_free_join, int with_insert) (\opt\litaihong\stonedb\storage\stonedb\core\engine_execute.cpp:181)
    stonedb::dbhandler::SDB_HandleSelect(THD * thd, LEX * lex, Query_result *& result, ulong setup_tables_done_option, int & res, int & optimize_after_sdb, int & sdb_free_join, int with_insert) (\opt\litaihong\stonedb\storage\stonedb\handler\ha_rcengine.cpp:82)
    mysql_execute_command(THD * thd, bool first_level) (\opt\litaihong\stonedb\sql\sql_parse.cc:3265)
    mysql_parse(THD * thd, Parser_state * parser_state) (\opt\litaihong\stonedb\sql\sql_parse.cc:5621)
    dispatch_command(THD * thd, const COM_DATA * com_data, enum_server_command command) (\opt\litaihong\stonedb\sql\sql_parse.cc:1495)
    do_command(THD * thd) (\opt\litaihong\stonedb\sql\sql_parse.cc:1034)
    handle_connection(void * arg) (\opt\litaihong\stonedb\sql\conn_handler\connection_handler_per_thread.cc:313)
    pfs_spawn_thread(void * arg) (\opt\litaihong\stonedb\storage\perfschema\pfs.cc:2197)
    libpthread.so.0!start_thread (未知源:0)
    libc.so.6!clone (未知源:0)

分析过程

assert(create_table->table == NULL);

Query_result_create::prepare (sql_insert.cc:2753)函数prepare阶段和optimize阶段在被调用了两次

1、stonedb::core::Engine::HandleSelect函数首先调用

st_select_lex_unit::prepare->prepare_fake_select_lex ->Query_result_create::prepare

此时create_table->table 是NULL。

2、然后调用

st_select_lex_unit::optimize_for_stonedb -> prepare_fake_select_lex -> Query_result_create::prepare

此时create_table->table不为NULL,assert(create_table->table == NULL); 导致数据库异常退出。

问题出现原因

分析st_select_lex_unit::optimize_for_stonedb函数发现是来源于MySQL的st_select_lex_unit::exec()函数

3、解决办法

mysql的handle_query函数先有prepare然后是optimize函数,但我们stonedb的optimize函数是根据MySQL的st_select_lex_unit::exec()写的,不知道为啥没有正常的optimize流程

【StoneDB研发日志】union功能bug记录

两种解决方案:

1、修改抛异常的代码行Query_result_create::prepare (sql_insert.cc:2753)函数

assert(create_table->table == NULL);

2、重写stonedb的st_select_lex_unit::optimize_for_stonedb函数,改动比较大,涉及功能多。

解决方案更新:

A:我们发现,这个问题是由于在优化器的代码中,Lex unit 两次prepare造成的。

首先我们抛弃了对assert语句修改的考虑,因为那里判断表没有创建是合理的。

于是解决方案有两种,

1:考虑在lex unit 的prepare里加入 is_prepared的判断。但这个方案,影响面很大,因为这个函数所有的语法都会影响到。

2:针对,select union 或者 select join,以及他们出现的复杂的组合做修改。发现了三处异常点需要进行is_prepared判断。1:union处。2:join处。3:fake_lex_prepare处。

B:针对我们的修改添加了相应mtr语句进行覆盖。一并记录在issue226中。

https://github.com/stoneatom/stonedb/issues/226

ADD test cases to cover these ctas queries for the following reason.

1: From code perspective. There are enough evidences that we want to support these ctas.

2: Our fix can cover these related queries.

CREATE TABLE t2 AS SELECT LEFT(f1,171) AS f2 FROM t1 UNION SELECT LEFT(f1,171) AS f2 FROM t1;

CREATE TABLE t3 AS SELECT t1.f1 AS f3 FROM t1 LEFT JOIN t2 ON t1.f1 = t2.f2;

CREATE TABLE t4 AS SELECT t1.f1 AS f4 FROM t1 INNER JOIN t2 ON t1.f1 = t2.f2;

CREATE TABLE t5 AS SELECT t1.f1 AS f5 FROM t1 RIGHT JOIN t2 ON t1.f1 = t2.f2;

CREATE TABLE t6 AS SELECT t1.f1 AS f6 FROM t1 UNION SELECT t2.f2 AS f6 FROM t2 LEFT JOIN t3 ON t2.f2 = t3.f3;

CREATE TABLE t7 AS SELECT t1.f1 AS f7 FROM t1 UNION SELECT t2.f2 AS f7 FROM t2 INNER JOIN t3 ON t2.f2 = t3.f3;

CREATE TABLE t8 AS SELECT t1.f1 AS f8 FROM t1 UNION SELECT t2.f2 AS f8 FROM t2 RIGHT JOIN t3 ON t2.f2 = t3.f3;

CREATE TABLE t9 AS SELECT t1.f1 AS f9 FROM t1 INNER JOIN t3 ON t1.f1 = t3.f3 UNION SELECT t2.f2 AS f9 FROM t2;

4、MySQL正常流程堆栈

Query_result_create::prepare(Query_result_create * const this, List & values, SELECT_LEX_UNIT * u) (\opt\litaihong\stonedb\sql\sql_insert.cc:2750)
st_select_lex::prepare(st_select_lex * const this, THD * thd) (\opt\litaihong\stonedb\sql\sql_resolver.cc:361)
st_select_lex_unit::prepare_fake_select_lex(st_select_lex_unit * const this, THD * thd_arg) (\opt\litaihong\stonedb\sql\sql_union.cc:441)
st_select_lex_unit::prepare(st_select_lex_unit * const this, THD * thd_arg, Query_result * sel_result, ulonglong added_options, ulonglong removed_options) (\opt\litaihong\stonedb\sql\sql_union.cc:670)
handle_query(THD * thd, LEX * lex, Query_result * result, ulonglong added_options, ulonglong removed_options, int optimize_after_bh, int free_join_from_bh) (\opt\litaihong\stonedb\sql\sql_select.cc:150)
mysql_execute_command(THD * thd, bool first_level) (\opt\litaihong\stonedb\sql\sql_parse.cc:3266)
mysql_parse(THD * thd, Parser_state * parser_state) (\opt\litaihong\stonedb\sql\sql_parse.cc:5621)
dispatch_command(THD * thd, const COM_DATA * com_data, enum_server_command command) (\opt\litaihong\stonedb\sql\sql_parse.cc:1495)
do_command(THD * thd) (\opt\litaihong\stonedb\sql\sql_parse.cc:1034)
handle_connection(void * arg) (\opt\litaihong\stonedb\sql\conn_handler\connection_handler_per_thread.cc:313)
pfs_spawn_thread(void * arg) (\opt\litaihong\stonedb\storage\perfschema\pfs.cc:2197)
libpthread.so.0!start_thread (未知源:0)
libc.so.6!clone (未知源:0)

Original: https://www.cnblogs.com/yangwilly/p/16591385.html
Author: 来来士
Title: 【StoneDB研发日志】union功能bug记录

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/505020/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • MySQL索引分类及相关概念辨析

    本文链接:https://www.cnblogs.com/ibigboy/p/16198243.html 之前的一篇《MySQL索引底层数据结构及原理深入分析》很受读者欢迎,成功地…

    数据库 2023年6月11日
    0103
  • 双色球系统开发

    Java对彩票双色球系统开发的简单实现 双色球系统 案例: 中奖条件及奖金表 代码及解释 main方法代码: public static void main(String[] ar…

    数据库 2023年6月16日
    0122
  • 新来的同时问我where 1=1是什么意思

    写在前面 之前在项目代码中写了一条sql查询语句,在where条件搜索中加入了where 1=1,新来的同事之后问我where 1=1 是什么意思,这样没意义啊,我笑了。今天来说明…

    数据库 2023年6月6日
    089
  • java企业官网源码 自适应响应式 freemarker 静态引擎 模块设计方案

    系统设计: 1.网站后台采用主流的 SSM 框架 jsp JSTL,网站后台采用freemaker静态化模版引擎生成html 2.因为是生成的html,所以访问速度快,轻便,对服务…

    数据库 2023年6月6日
    0293
  • Test post from Metablog Api

    This is the body of the post posted on2011-02-06 17:25 迷你软件 阅读(328 ) 评论() 编辑 本网站绝大部分资源来源于I…

    数据库 2023年6月11日
    093
  • Linux–>定时任务调度

    指定系统在某个时间执行特点的命令或程序。 任务调度分类: crontab 选项 常用选项 选项 说明 -e 编辑crontab定时任务 -l 查询crontab任务 -r 删除当前…

    数据库 2023年6月14日
    070
  • Spring Boot 入门

    一、 Spring Boot 入门 1、Spring Boot 简介 简化Spring应用开发的一个框架;整个Spring技术栈的一个大整合;J2EE开发的一站式解决方案; 2、微…

    数据库 2023年6月6日
    0153
  • [javaweb]重点总结大全

    javaweb web:网页静态web:html,css 数据不会发生变化动态web:servlet/jsp,asp,php每个人在不同的时间看到数据都不同 web应用程序编写完毕…

    数据库 2023年6月16日
    083
  • 使用JMeter进行MySQL的压力测试

    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源。 GreatSQL是MySQL的国产分支版本,使用上与MySQL一致。 前言 1. JMeter安装 2…

    数据库 2023年5月24日
    097
  • 阿里云服务器中MySQL数据库被攻击

    前几天刚领了一个月的阿里云服务器玩,在里面装了MySQL,然后这几天找了个小项目练习着玩呢,就将表建在里面了。刚访问添加员工还好好的,刚给员工分页查询呢 ,啪一下 ,很突然昂 ,就…

    数据库 2023年6月11日
    097
  • Django配置日志功能

    Django配置日志功能 LOGGING = { ‘version’: 1, ‘disable_existing_loggers’: False, # 是否禁用已经存在的日志器 ‘…

    数据库 2023年6月14日
    0102
  • Linux 下统计文件夹下文件的数量

    1、查看当前目录下的文件数量(不包含子目录中的文件) 2、查看当前目录下的文件数量(包含子目录中的文件) 3、 查看当前目录下的文件夹目录个数(不包含子目录中的目录),同上述理,如…

    数据库 2023年6月14日
    082
  • 剑指 Offer II 091. 粉刷房子

    剑指 Offer II 091. 粉刷房子 动态规划当前粉刷房子的花费可以由上一家粉刷房子的花费推导出来,所以可以使用动态规划求解这道题。首先确定dp数组的含义,每个房子都可以被粉…

    数据库 2023年6月16日
    0108
  • 多商户商城系统功能拆解27讲-平台端分销结算设置

    多商户商城系统,也称为B2B2C(BBC)平台电商模式多商家商城系统。可以快速帮助企业搭建类似拼多多/京东/天猫/淘宝的综合商城。 多商户商城系统支持商家入驻加盟,同时满足平台自营…

    数据库 2023年6月14日
    093
  • JUC学习笔记(八)

    JUC学习笔记(一)https://www.cnblogs.com/lm66/p/15118407.htmlJUC学习笔记(二)https://www.cnblogs.com/lm…

    数据库 2023年6月6日
    091
  • 线程的同步

    线程同步机制同步块:Java中提供了同步机制,可以有效的防止资源冲突。同步机制使用 synchronized关键字 使用该关键字的代码块称为同步块。同步块 语法: synchron…

    数据库 2023年6月16日
    0127
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球