1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

[MCOL-4699] Add support for circular outer joins.

This commit is contained in:
Denis Khalikov
2022-04-01 19:40:50 +03:00
parent ef8337fd60
commit 636e60b5f9
7 changed files with 971 additions and 183 deletions

View File

@ -28,6 +28,7 @@
#include <stack> #include <stack>
#include <string> #include <string>
#include <vector> #include <vector>
#include <unordered_map>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid.hpp>
@ -365,6 +366,10 @@ struct JobInfo
std::vector<execplan::ParseTree*> dynamicParseTreeVec; std::vector<execplan::ParseTree*> dynamicParseTreeVec;
PrimitiveServerThreadPools primitiveServerThreadPools; PrimitiveServerThreadPools primitiveServerThreadPools;
// Represents a `join edges` and `join id` to be restored in `join order` part.
std::map<std::pair<uint32_t, uint32_t>, uint32_t> joinEdgesToRestore;
// Represents a pair of `table` to be on a large side and weight associated with that table.
std::unordered_map<uint32_t, uint32_t> tablesForLargeSide;
private: private:
// defaults okay // defaults okay

File diff suppressed because it is too large Load Diff

View File

@ -128,19 +128,31 @@ void orExpresssion(const execplan::Operator* op, JobInfo& jobInfo);
// union the queries and return the tuple union step // union the queries and return the tuple union step
SJSTEP unionQueries(JobStepVector& queries, uint64_t distinctUnionNum, JobInfo& jobInfo); SJSTEP unionQueries(JobStepVector& queries, uint64_t distinctUnionNum, JobInfo& jobInfo);
// Used for join graph analysis.
// WHITE - node is not processed.
// GREY - node is in process.
// BLACK - node is done.
enum class JoinTableColor
{
WHITE,
GREY,
BLACK
};
struct JoinTableNode struct JoinTableNode
{ {
bool fVisited; JoinTableColor fTableColor;
uint32_t fParent; uint32_t fParent;
std::vector<uint32_t> fAdjacentList; std::vector<uint32_t> fAdjacentList;
JoinTableNode() : fVisited(false), fParent(-1) JoinTableNode() : fTableColor(JoinTableColor::WHITE), fParent(UINT_MAX)
{ {
} }
}; };
using JoinGraph = std::map<uint32_t, JoinTableNode>; using JoinGraph = std::map<uint32_t, JoinTableNode>;
using JoinEdges = std::set<pair<uint32_t, uint32_t>>; using JoinEdge = std::pair<uint32_t, uint32_t>;
using Cycles = std::vector<std::vector<std::pair<uint32_t, uint32_t>>>; using JoinEdges = std::set<JoinEdge>;
using Cycle = std::vector<std::pair<uint32_t, uint32_t>>; using Cycle = std::vector<JoinEdge>;
using PostJoinFilterKeys = std::vector<std::pair<std::pair<uint32_t, uint32_t>, std::vector<uint32_t>>>; using Cycles = std::vector<std::vector<JoinEdge>>;
using PostJoinFilterKeys = std::vector<std::pair<JoinEdge, std::vector<uint32_t>>>;
} // namespace joblist } // namespace joblist

View File

@ -1092,7 +1092,8 @@ const string TupleHashJoinStep::toString() const
{ {
ostringstream oss; ostringstream oss;
size_t idlsz = fInputJobStepAssociation.outSize(); size_t idlsz = fInputJobStepAssociation.outSize();
idbassert(idlsz > 1); // Avoid assertion on empty `TupleHashJoinStep`.
idbassert(idlsz > 1 || idlsz == 0);
oss << "TupleHashJoinStep ses:" << fSessionId << " st:" << fStepId; oss << "TupleHashJoinStep ses:" << fSessionId << " st:" << fStepId;
oss << omitOidInDL; oss << omitOidInDL;
@ -1184,6 +1185,7 @@ void TupleHashJoinStep::configJoinKeyIndex(const vector<JoinType>& jt, const vec
{ {
joinTypes.insert(joinTypes.begin(), jt.begin(), jt.end()); joinTypes.insert(joinTypes.begin(), jt.begin(), jt.end());
typelessJoin.insert(typelessJoin.begin(), typeless.begin(), typeless.end()); typelessJoin.insert(typelessJoin.begin(), typeless.begin(), typeless.end());
smallSideKeys.insert(smallSideKeys.begin(), smallkey.begin(), smallkey.end()); smallSideKeys.insert(smallSideKeys.begin(), smallkey.begin(), smallkey.end());
largeSideKeys.insert(largeSideKeys.begin(), largekey.begin(), largekey.end()); largeSideKeys.insert(largeSideKeys.begin(), largekey.begin(), largekey.end());
#ifdef JLF_DEBUG #ifdef JLF_DEBUG

View File

@ -0,0 +1,133 @@
DROP DATABASE IF EXISTS mcol4699;
CREATE DATABASE mcol4699;
USE mcol4699;
create table t1 (a int, b int) engine=columnstore;
create table t2 (a int, b int) engine=columnstore;
create table t3 (a int, b int) engine=columnstore;
create table t4 (a int, b int) engine=columnstore;
create table t5 (a int, b int) engine=columnstore;
create table t6 (a int, b int) engine=columnstore;
create table t7 (a int, b int) engine=columnstore;
create table t8 (a int, b int) engine=columnstore;
create table t9 (a int, b int) engine=columnstore;
insert into t1 values (1, 3), (2, 3), (3, 4);
insert into t2 values (1, 2), (2, 4), (4, 5);
insert into t3 values (1, 2), (2, 3), (3, 4), (4, 5);
insert into t4 values (1, 3);
insert into t5 values (1, 2), (3, 4);
insert into t6 values (1, 2), (3, 4);
insert into t7 values (1, 3);
insert into t8 values (1, 3);
insert into t9 values (1, 2);
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b);
a b a b a b
1 3 1 2 1 2
NULL NULL NULL NULL 2 3
NULL NULL NULL NULL 3 4
NULL NULL NULL NULL 4 5
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) left join t4 on (t3.a = t4.a);
a b a b a b a b
1 3 1 2 1 2 1 3
NULL NULL NULL NULL 2 3 NULL NULL
NULL NULL NULL NULL 3 4 NULL NULL
NULL NULL NULL NULL 4 5 NULL NULL
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) where (t3.a = 1 or t3.a = 3);
a b a b a b
1 3 1 2 1 2
NULL NULL NULL NULL 3 4
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) where (t3.a > 1);
a b a b a b
NULL NULL NULL NULL 2 3
NULL NULL NULL NULL 3 4
NULL NULL NULL NULL 4 5
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t2.a = t3.a) left join t4 on (t3.a = t4.a and t1.b = t4.b) order by t3.a;
a b a b a b a b
1 3 1 2 1 2 1 3
2 3 2 4 2 3 NULL NULL
NULL NULL NULL NULL 3 4 NULL NULL
NULL NULL NULL NULL 4 5 NULL NULL
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t2.a = t3.a) left join t4 on (t3.a = t4.a and t2.b = t4.b) order by t3.a;
a b a b a b a b
1 3 1 2 1 2 NULL NULL
2 3 2 4 2 3 NULL NULL
NULL NULL NULL NULL 3 4 NULL NULL
NULL NULL NULL NULL 4 5 NULL NULL
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b and t3.a > t1.a);
a b a b a b
NULL NULL NULL NULL 1 2
NULL NULL NULL NULL 2 3
NULL NULL NULL NULL 3 4
NULL NULL NULL NULL 4 5
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b and t3.a > t2.a and t3.a > t1.a);
a b a b a b
NULL NULL NULL NULL 1 2
NULL NULL NULL NULL 2 3
NULL NULL NULL NULL 3 4
NULL NULL NULL NULL 4 5
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b and t3.b > t2.a and t3.a < t1.b);
a b a b a b
1 3 1 2 1 2
NULL NULL NULL NULL 2 3
NULL NULL NULL NULL 3 4
NULL NULL NULL NULL 4 5
select * from t1 left join t2 on (t1.a = t2.a) left join t3 on (t2.a = t3.a) left join t4 on (t4.a = t3.a) left join t5 on (t5.a = t2.a) left join t6 on (t5.a = t6.a and t6.a = t4.a);
a b a b a b a b a b a b
1 3 1 2 1 2 1 3 1 2 1 2
2 3 2 4 2 3 NULL NULL NULL NULL NULL NULL
3 4 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) left join t4 on (t3.a = t4.a and t2.a = t4.a) order by t3.a;
a b a b a b a b
1 3 1 2 1 2 1 3
NULL NULL NULL NULL 2 3 NULL NULL
NULL NULL NULL NULL 3 4 NULL NULL
NULL NULL NULL NULL 4 5 NULL NULL
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) right join t4 on (t3.a = t4.a and t2.a = t4.a) order by t3.a;
a b a b a b a b
1 3 1 2 1 2 1 3
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a) left join t4 on (t3.a = t4.a and t1.a = t4.a and t2.a = t4.a);
a b a b a b a b
1 3 1 2 1 2 1 3
2 3 2 4 2 3 NULL NULL
NULL NULL NULL NULL 3 4 NULL NULL
NULL NULL NULL NULL 4 5 NULL NULL
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a) right join t4 on (t3.a = t4.a and t1.a = t4.a and t2.a = t4.a);
a b a b a b a b
1 3 1 2 1 2 1 3
select * from t1 left join t2 on (t1.a = t2.a) left join t3 on (t2.a = t3.a) left join t4 on (t4.a = t3.a) left join t5 on (t5.a = t2.a) left join t6 on (t5.a = t6.a and t6.a = t4.a) left join t7 on (t7.a = t3.a) left join t8 on (t8.a = t7.a and t8.a = t2.a);
a b a b a b a b a b a b a b a b
1 3 1 2 1 2 1 3 1 2 1 2 1 3 1 3
2 3 2 4 2 3 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
3 4 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) left join t4 on (t3.a = t4.a and t2.a = t4.a) left join t5 on (t4.a = t5.a and t3.b = t5.b);
a b a b a b a b a b
1 3 1 2 1 2 1 3 1 2
NULL NULL NULL NULL 2 3 NULL NULL NULL NULL
NULL NULL NULL NULL 3 4 NULL NULL NULL NULL
NULL NULL NULL NULL 4 5 NULL NULL NULL NULL
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) left join t4 on (t3.a = t4.a and t2.a = t4.a) right join t5 on (t4.a = t5.a and t3.b = t5.b);
a b a b a b a b a b
1 3 1 2 1 2 1 3 1 2
NULL NULL NULL NULL NULL NULL NULL NULL 3 4
select * from t1 left join t2 on (t1.a = t2.a) left join t3 on (t2.a = t3.a) left join t4 on (t4.a = t3.a) left join t5 on (t5.a = t2.a) left join t6 on (t5.a = t6.a and t6.a = t4.a) left join t7 on (t7.a = t3.a) left join t8 on (t8.a = t7.a and t8.a = t2.a) left join t9 on (t7.a = t9.a and t4.a = t9.a);
a b a b a b a b a b a b a b a b a b
1 3 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2
2 3 2 4 2 3 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
3 4 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) left join t4 on (t3.a = t4.a and t2.a = t4.a) right join t5 on (t4.a = t5.a and t3.b = t5.b) right join t6 on (t5.a = t6.a and t4.a = t6.a);
a b a b a b a b a b a b
1 3 1 2 1 2 1 3 1 2 1 2
NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 3 4
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) left join t4 on (t3.a = t4.a and t2.a = t4.a) right join t5 on (t4.a = t5.a and t3.b = t5.b) left join t6 on (t5.a = t6.a and t4.a = t6.a);
a b a b a b a b a b a b
1 3 1 2 1 2 1 3 1 2 1 2
NULL NULL NULL NULL NULL NULL NULL NULL 3 4 NULL NULL
drop table t1;
drop table t2;
drop table t3;
drop table t4;
drop table t5;
drop table t6;
drop table t7;
drop table t8;
drop table t9;
DROP DATABASE mcol4699;

View File

@ -0,0 +1,70 @@
#-- source ../include/have_columnstore.inc
--disable_warnings
DROP DATABASE IF EXISTS mcol4699;
--enable_warnings
CREATE DATABASE mcol4699;
USE mcol4699;
create table t1 (a int, b int) engine=columnstore;
create table t2 (a int, b int) engine=columnstore;
create table t3 (a int, b int) engine=columnstore;
create table t4 (a int, b int) engine=columnstore;
create table t5 (a int, b int) engine=columnstore;
create table t6 (a int, b int) engine=columnstore;
create table t7 (a int, b int) engine=columnstore;
create table t8 (a int, b int) engine=columnstore;
create table t9 (a int, b int) engine=columnstore;
insert into t1 values (1, 3), (2, 3), (3, 4);
insert into t2 values (1, 2), (2, 4), (4, 5);
insert into t3 values (1, 2), (2, 3), (3, 4), (4, 5);
insert into t4 values (1, 3);
insert into t5 values (1, 2), (3, 4);
insert into t6 values (1, 2), (3, 4);
insert into t7 values (1, 3);
insert into t8 values (1, 3);
insert into t9 values (1, 2);
# 1 cycle.
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b);
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) left join t4 on (t3.a = t4.a);
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) where (t3.a = 1 or t3.a = 3);
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) where (t3.a > 1);
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t2.a = t3.a) left join t4 on (t3.a = t4.a and t1.b = t4.b) order by t3.a;
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t2.a = t3.a) left join t4 on (t3.a = t4.a and t2.b = t4.b) order by t3.a;
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b and t3.a > t1.a);
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b and t3.a > t2.a and t3.a > t1.a);
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b and t3.b > t2.a and t3.a < t1.b);
select * from t1 left join t2 on (t1.a = t2.a) left join t3 on (t2.a = t3.a) left join t4 on (t4.a = t3.a) left join t5 on (t5.a = t2.a) left join t6 on (t5.a = t6.a and t6.a = t4.a);
# 2 cycles.
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) left join t4 on (t3.a = t4.a and t2.a = t4.a) order by t3.a;
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) right join t4 on (t3.a = t4.a and t2.a = t4.a) order by t3.a;
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a) left join t4 on (t3.a = t4.a and t1.a = t4.a and t2.a = t4.a);
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a) right join t4 on (t3.a = t4.a and t1.a = t4.a and t2.a = t4.a);
select * from t1 left join t2 on (t1.a = t2.a) left join t3 on (t2.a = t3.a) left join t4 on (t4.a = t3.a) left join t5 on (t5.a = t2.a) left join t6 on (t5.a = t6.a and t6.a = t4.a) left join t7 on (t7.a = t3.a) left join t8 on (t8.a = t7.a and t8.a = t2.a);
# 3 cycles.
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) left join t4 on (t3.a = t4.a and t2.a = t4.a) left join t5 on (t4.a = t5.a and t3.b = t5.b);
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) left join t4 on (t3.a = t4.a and t2.a = t4.a) right join t5 on (t4.a = t5.a and t3.b = t5.b);
select * from t1 left join t2 on (t1.a = t2.a) left join t3 on (t2.a = t3.a) left join t4 on (t4.a = t3.a) left join t5 on (t5.a = t2.a) left join t6 on (t5.a = t6.a and t6.a = t4.a) left join t7 on (t7.a = t3.a) left join t8 on (t8.a = t7.a and t8.a = t2.a) left join t9 on (t7.a = t9.a and t4.a = t9.a);
# 4 cycles.
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) left join t4 on (t3.a = t4.a and t2.a = t4.a) right join t5 on (t4.a = t5.a and t3.b = t5.b) right join t6 on (t5.a = t6.a and t4.a = t6.a);
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b) left join t4 on (t3.a = t4.a and t2.a = t4.a) right join t5 on (t4.a = t5.a and t3.b = t5.b) left join t6 on (t5.a = t6.a and t4.a = t6.a);
drop table t1;
drop table t2;
drop table t3;
drop table t4;
drop table t5;
drop table t6;
drop table t7;
drop table t8;
drop table t9;
DROP DATABASE mcol4699;

View File

@ -22,7 +22,6 @@
1000 ERR_MISS_JOIN %1% not joined. 1000 ERR_MISS_JOIN %1% not joined.
1001 ERR_NON_SUPPORTED_FUNCTION Function '%1%' isn't supported. 1001 ERR_NON_SUPPORTED_FUNCTION Function '%1%' isn't supported.
1002 ERR_INCOMPATIBLE_JOIN %1% incompatible column type specified for join condition. 1002 ERR_INCOMPATIBLE_JOIN %1% incompatible column type specified for join condition.
1003 ERR_CIRCULAR_JOIN Circular joins are not supported.
1004 ERR_MIX_JOIN Mixed %1% JOIN is not supported. 1004 ERR_MIX_JOIN Mixed %1% JOIN is not supported.
1005 ERR_UPDATE_SUB update with subselect in select clause is currently not supported in Columnstore. 1005 ERR_UPDATE_SUB update with subselect in select clause is currently not supported in Columnstore.
1006 ERR_DATATYPE_NOT_SUPPORT Function called with unsupported datatype. 1006 ERR_DATATYPE_NOT_SUPPORT Function called with unsupported datatype.