Skip to content

Commit

Permalink
feat(tianmu):improve the code quality and refactoring derived table o…
Browse files Browse the repository at this point in the history
…ptimize for tianmu(stoneatom#1277, stoneatom#1276, stoneatom#1258)

 #   feat(tianmu): add multi-thread aggregation of group by (stoneatom#422) (stoneatom#1279)

 #   feat(tianmu): add multi-thread aggregation of group by (stoneatom#422) (stoneatom#1279)
  • Loading branch information
isredstar committed Feb 15, 2023
1 parent 36fbc22 commit 7321460
Show file tree
Hide file tree
Showing 15 changed files with 588 additions and 379 deletions.
43 changes: 43 additions & 0 deletions mysql-test/suite/tianmu/r/issue1258.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
DROP DATABASE IF EXISTS issue1258_test;
CREATE DATABASE issue1258_test;
USE issue1258_test;
set sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
Warnings:
Warning 3135 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
CREATE TABLE `t_test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(10) NOT NULL,
`last_name` varchar(10) NOT NULL,
`sex` varchar(5) NOT NULL,
`score` int(11) NOT NULL,
`copy_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4;
insert into t_test values(1,"syz1","stonedb1","nan",99,21);
insert into t_test values(2,"syz2","stonedb2","nan",99,22);
insert into t_test values(3,"syz3","stonedb3","nan",99,23);
insert into t_test values(4,"syz4","stonedb4","nan",99,24);
insert into t_test values(5,"syz5","stonedb5","nan",99,25);
SELECT
bb.first_name,
bb.last_name
FROM
(
SELECT
count(a.first_name ) AS first_name,
SUBSTR( a.last_name, 1, 10 ) AS last_name
FROM
t_test a,
t_test b
WHERE
a.id = b.id
GROUP BY
SUBSTR( a.last_name, 1, 10 )
) bb;
first_name last_name
1 stonedb1
1 stonedb2
1 stonedb3
1 stonedb4
1 stonedb5
DROP DATABASE issue1258_test;
46 changes: 46 additions & 0 deletions mysql-test/suite/tianmu/t/issue1258.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--source include/have_tianmu.inc

--disable_warnings
DROP DATABASE IF EXISTS issue1258_test;
--enable_warnings

CREATE DATABASE issue1258_test;

USE issue1258_test;

set sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

CREATE TABLE `t_test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(10) NOT NULL,
`last_name` varchar(10) NOT NULL,
`sex` varchar(5) NOT NULL,
`score` int(11) NOT NULL,
`copy_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4;

insert into t_test values(1,"syz1","stonedb1","nan",99,21);
insert into t_test values(2,"syz2","stonedb2","nan",99,22);
insert into t_test values(3,"syz3","stonedb3","nan",99,23);
insert into t_test values(4,"syz4","stonedb4","nan",99,24);
insert into t_test values(5,"syz5","stonedb5","nan",99,25);

SELECT
bb.first_name,
bb.last_name
FROM
(
SELECT
count(a.first_name ) AS first_name,
SUBSTR( a.last_name, 1, 10 ) AS last_name
FROM
t_test a,
t_test b
WHERE
a.id = b.id
GROUP BY
SUBSTR( a.last_name, 1, 10 )
) bb;

DROP DATABASE issue1258_test;
1 change: 0 additions & 1 deletion sql/sql_derived.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ bool TABLE_LIST::optimize_derived(THD *thd)
DBUG_RETURN(false);
}


/**
Create result table for a materialized derived table/view.
Expand Down
5 changes: 3 additions & 2 deletions sql/sql_lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,10 @@ class st_select_lex_unit: public Sql_alloc
bool prepare(THD *thd, Query_result *result, ulonglong added_options,
ulonglong removed_options);
bool optimize(THD *thd);
//TIANMU UPGRADE END

int optimize_for_tianmu();
int optimize_after_tianmu();
//END

bool execute(THD *thd);
bool explain(THD *ethd);
bool cleanup(bool full);
Expand Down Expand Up @@ -1416,6 +1416,7 @@ class st_select_lex: public Sql_alloc
bool setup_conds(THD *thd);
bool prepare(THD *thd);
bool optimize(THD *thd);
bool optimize_select_for_tianmu(THD *thd);
void reset_nj_counters(List<TABLE_LIST> *join_list= NULL);
bool check_only_full_group_by(THD *thd);

Expand Down
Loading

0 comments on commit 7321460

Please sign in to comment.