Skip to content

Commit

Permalink
MDEV-10141: Add support for INTERSECT (and common parts for EXCEPT)
Browse files Browse the repository at this point in the history
MDEV-10140: Add support for EXCEPT
  • Loading branch information
sanja-byelkin committed Mar 14, 2017
1 parent e43156e commit 05d3c3d
Show file tree
Hide file tree
Showing 93 changed files with 3,153 additions and 898 deletions.
6 changes: 6 additions & 0 deletions include/m_string.h
Expand Up @@ -230,6 +230,12 @@ static inline void lex_string_set(LEX_STRING *lex_str, const char *c_str)
lex_str->str= (char *) c_str;
lex_str->length= strlen(c_str);
}
static inline void lex_string_set3(LEX_STRING *lex_str, const char *c_str,
size_t len)
{
lex_str->str= (char *) c_str;
lex_str->length= len;
}

#ifdef __cplusplus
static inline char *safe_str(char *str)
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/include/gis_generic.inc
Expand Up @@ -236,7 +236,7 @@ SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrwithin FROM t1 a1 JOIN t1
SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS contains FROM t1 a1 JOIN t1 a2 ON Contains( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS disjoint FROM t1 a1 JOIN t1 a2 ON Disjoint( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS equals FROM t1 a1 JOIN t1 a2 ON Equals( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS intersect FROM t1 a1 JOIN t1 a2 ON Intersects( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS intersects FROM t1 a1 JOIN t1 a2 ON Intersects( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS overlaps FROM t1 a1 JOIN t1 a2 ON Overlaps( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS touches FROM t1 a1 JOIN t1 a2 ON Touches( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS within FROM t1 a1 JOIN t1 a2 ON Within( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
Expand Down
1 change: 1 addition & 0 deletions mysql-test/r/analyze_format_json.result
Expand Up @@ -451,6 +451,7 @@ ANALYZE
{
"query_block": {
"select_id": 2,
"operation": "UNION",
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"table": {
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/r/compare.result
Expand Up @@ -88,7 +88,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
Warnings:
Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t2`.`a` AS `a`,<expr_cache><`test`.`t2`.`a`>((select count(0) from `test`.`t1` where `test`.`t1`.`b` = `test`.`t2`.`a` and concat(`test`.`t1`.`b`,`test`.`t1`.`c`) = concat('0',`test`.`t2`.`a`,'01'))) AS `x` from `test`.`t2` order by `test`.`t2`.`a`
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,<expr_cache><`test`.`t2`.`a`>((/* select#2 */ select count(0) from `test`.`t1` where `test`.`t1`.`b` = `test`.`t2`.`a` and concat(`test`.`t1`.`b`,`test`.`t1`.`c`) = concat('0',`test`.`t2`.`a`,'01'))) AS `x` from `test`.`t2` order by `test`.`t2`.`a`
DROP TABLE t1,t2;
CREATE TABLE t1 (a TIMESTAMP);
INSERT INTO t1 VALUES (NOW()),(NOW()),(NOW());
Expand Down
15 changes: 13 additions & 2 deletions mysql-test/r/cte_recursive.result
Expand Up @@ -699,7 +699,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
NULL UNION RESULT <union3,4,5> ALL NULL NULL NULL NULL NULL NULL
2 UNCACHEABLE SUBQUERY <derived3> ALL NULL NULL NULL NULL 12 100.00 Using where
Warnings:
Note 1003 with recursive ancestor_couple_ids as (select `a`.`father` AS `h_id`,`a`.`mother` AS `w_id` from `coupled_ancestors` `a` where `a`.`father` is not null and `a`.`mother` is not null), coupled_ancestors as (select `test`.`folks`.`id` AS `id`,`test`.`folks`.`name` AS `name`,`test`.`folks`.`dob` AS `dob`,`test`.`folks`.`father` AS `father`,`test`.`folks`.`mother` AS `mother` from `test`.`folks` where `test`.`folks`.`name` = 'Me' union all select `test`.`p`.`id` AS `id`,`test`.`p`.`name` AS `name`,`test`.`p`.`dob` AS `dob`,`test`.`p`.`father` AS `father`,`test`.`p`.`mother` AS `mother` from `test`.`folks` `p` join `ancestor_couple_ids` `fa` where `test`.`p`.`id` = `fa`.`h_id` union all select `test`.`p`.`id` AS `id`,`test`.`p`.`name` AS `name`,`test`.`p`.`dob` AS `dob`,`test`.`p`.`father` AS `father`,`test`.`p`.`mother` AS `mother` from `test`.`folks` `p` join `ancestor_couple_ids` `ma` where `test`.`p`.`id` = `ma`.`w_id`)select `h`.`name` AS `name`,`h`.`dob` AS `dob`,`w`.`name` AS `name`,`w`.`dob` AS `dob` from `ancestor_couple_ids` `c` join `coupled_ancestors` `h` join `coupled_ancestors` `w` where `h`.`id` = `c`.`h_id` and `w`.`id` = `c`.`w_id`
Note 1003 with recursive ancestor_couple_ids as (/* select#2 */ select `a`.`father` AS `h_id`,`a`.`mother` AS `w_id` from `coupled_ancestors` `a` where `a`.`father` is not null and `a`.`mother` is not null), coupled_ancestors as (/* select#3 */ select `test`.`folks`.`id` AS `id`,`test`.`folks`.`name` AS `name`,`test`.`folks`.`dob` AS `dob`,`test`.`folks`.`father` AS `father`,`test`.`folks`.`mother` AS `mother` from `test`.`folks` where `test`.`folks`.`name` = 'Me' union all /* select#4 */ select `test`.`p`.`id` AS `id`,`test`.`p`.`name` AS `name`,`test`.`p`.`dob` AS `dob`,`test`.`p`.`father` AS `father`,`test`.`p`.`mother` AS `mother` from `test`.`folks` `p` join `ancestor_couple_ids` `fa` where `test`.`p`.`id` = `fa`.`h_id` union all /* select#5 */ select `test`.`p`.`id` AS `id`,`test`.`p`.`name` AS `name`,`test`.`p`.`dob` AS `dob`,`test`.`p`.`father` AS `father`,`test`.`p`.`mother` AS `mother` from `test`.`folks` `p` join `ancestor_couple_ids` `ma` where `test`.`p`.`id` = `ma`.`w_id`)/* select#1 */ select `h`.`name` AS `name`,`h`.`dob` AS `dob`,`w`.`name` AS `name`,`w`.`dob` AS `dob` from `ancestor_couple_ids` `c` join `coupled_ancestors` `h` join `coupled_ancestors` `w` where `h`.`id` = `c`.`h_id` and `w`.`id` = `c`.`w_id`
# simple mutual recursion
with recursive
ancestor_couple_ids(h_id, w_id)
Expand Down Expand Up @@ -882,7 +882,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
3 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 12 100.00 Using where; Using join buffer (flat, BNL join)
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
Warnings:
Note 1003 with recursive ancestors as (select `test`.`folks`.`id` AS `id`,`test`.`folks`.`name` AS `name`,`test`.`folks`.`dob` AS `dob`,`test`.`folks`.`father` AS `father`,`test`.`folks`.`mother` AS `mother` from `test`.`folks` where `test`.`folks`.`name` = 'Me' and `test`.`folks`.`dob` = DATE'2000-01-01' union select `p`.`id` AS `id`,`p`.`name` AS `name`,`p`.`dob` AS `dob`,`p`.`father` AS `father`,`p`.`mother` AS `mother` from `test`.`folks` `p` join `ancestors` `a` where `a`.`father` = `p`.`id` or `a`.`mother` = `p`.`id`)select `ancestors`.`id` AS `id`,`ancestors`.`name` AS `name`,`ancestors`.`dob` AS `dob`,`ancestors`.`father` AS `father`,`ancestors`.`mother` AS `mother` from `ancestors`
Note 1003 with recursive ancestors as (/* select#2 */ select `test`.`folks`.`id` AS `id`,`test`.`folks`.`name` AS `name`,`test`.`folks`.`dob` AS `dob`,`test`.`folks`.`father` AS `father`,`test`.`folks`.`mother` AS `mother` from `test`.`folks` where `test`.`folks`.`name` = 'Me' and `test`.`folks`.`dob` = DATE'2000-01-01' union /* select#3 */ select `p`.`id` AS `id`,`p`.`name` AS `name`,`p`.`dob` AS `dob`,`p`.`father` AS `father`,`p`.`mother` AS `mother` from `test`.`folks` `p` join `ancestors` `a` where `a`.`father` = `p`.`id` or `a`.`mother` = `p`.`id`)/* select#1 */ select `ancestors`.`id` AS `id`,`ancestors`.`name` AS `name`,`ancestors`.`dob` AS `dob`,`ancestors`.`father` AS `father`,`ancestors`.`mother` AS `mother` from `ancestors`
# recursive spec with two anchor selects and two recursive ones
with recursive
ancestor_ids (id)
Expand Down Expand Up @@ -1353,6 +1353,7 @@ EXPLAIN
{
"query_block": {
"select_id": 4,
"operation": "UNION",
"table": {
"table_name": "folks",
"access_type": "ALL",
Expand All @@ -1365,6 +1366,7 @@ EXPLAIN
{
"query_block": {
"select_id": 6,
"operation": "UNION",
"table": {
"table_name": "<derived3>",
"access_type": "ALL",
Expand All @@ -1380,6 +1382,7 @@ EXPLAIN
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"table": {
"table_name": "folks",
"access_type": "ALL",
Expand All @@ -1392,6 +1395,7 @@ EXPLAIN
{
"query_block": {
"select_id": 2,
"operation": "UNION",
"table": {
"table_name": "folks",
"access_type": "ALL",
Expand Down Expand Up @@ -1423,6 +1427,7 @@ EXPLAIN
{
"query_block": {
"select_id": 5,
"operation": "UNION",
"table": {
"table_name": "<derived4>",
"access_type": "ALL",
Expand Down Expand Up @@ -1484,6 +1489,7 @@ EXPLAIN
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"table": {
"table_name": "v",
"access_type": "ALL",
Expand Down Expand Up @@ -1518,6 +1524,7 @@ EXPLAIN
{
"query_block": {
"select_id": 2,
"operation": "UNION",
"table": {
"table_name": "<derived4>",
"access_type": "ALL",
Expand Down Expand Up @@ -1750,6 +1757,7 @@ EXPLAIN
{
"query_block": {
"select_id": 2,
"operation": "UNION",
"table": {
"table_name": "t1",
"access_type": "ALL",
Expand All @@ -1761,6 +1769,7 @@ EXPLAIN
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"table": {
"table_name": "<derived2>",
"access_type": "ALL",
Expand Down Expand Up @@ -2378,6 +2387,7 @@ ANALYZE
{
"query_block": {
"select_id": 2,
"operation": "UNION",
"table": {
"message": "No tables used"
}
Expand All @@ -2386,6 +2396,7 @@ ANALYZE
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"r_loops": 10,
"r_total_time_ms": "REPLACED",
"table": {
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/r/derived.result
Expand Up @@ -632,7 +632,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
2 DERIVED t1 system NULL NULL NULL NULL 1 100.00
Warnings:
Note 1276 Field or reference 'sq.f2' of SELECT #3 was resolved in SELECT #1
Note 1003 select 6 AS `f1` from <materialize> (select `test`.`t2`.`f3` from `test`.`t2` having `test`.`t2`.`f3` >= 8) semi join (`test`.`t2`) where `test`.`t2`.`f3` = 6 and `<subquery4>`.`f3` = 9
Note 1003 /* select#1 */ select 6 AS `f1` from <materialize> (/* select#4 */ select `test`.`t2`.`f3` from `test`.`t2` having `test`.`t2`.`f3` >= 8) semi join (`test`.`t2`) where `test`.`t2`.`f3` = 6 and `<subquery4>`.`f3` = 9
DROP TABLE t2,t1;
#
# MDEV-9462: Out of memory using explain on 2 empty tables
Expand Down
18 changes: 17 additions & 1 deletion mysql-test/r/derived_cond_pushdown.result
Expand Up @@ -4111,6 +4111,7 @@ EXPLAIN
{
"query_block": {
"select_id": 2,
"operation": "UNION",
"table": {
"table_name": "t2",
"access_type": "ALL",
Expand Down Expand Up @@ -4254,6 +4255,7 @@ EXPLAIN
{
"query_block": {
"select_id": 2,
"operation": "UNION",
"table": {
"table_name": "t2",
"access_type": "ALL",
Expand Down Expand Up @@ -4408,6 +4410,7 @@ EXPLAIN
{
"query_block": {
"select_id": 2,
"operation": "UNION",
"table": {
"table_name": "t2",
"access_type": "ALL",
Expand Down Expand Up @@ -4564,6 +4567,7 @@ EXPLAIN
{
"query_block": {
"select_id": 2,
"operation": "UNION",
"table": {
"table_name": "t2",
"access_type": "ALL",
Expand Down Expand Up @@ -4607,6 +4611,7 @@ EXPLAIN
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"table": {
"table_name": "t2",
"access_type": "ALL",
Expand Down Expand Up @@ -4730,6 +4735,7 @@ EXPLAIN
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"having_condition": "c < 300 and c > 100",
"filesort": {
"sort_key": "t1.a, t1.b",
Expand Down Expand Up @@ -4838,6 +4844,7 @@ EXPLAIN
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"having_condition": "c < 300 and (t1.a < 2 or c > 800)",
"filesort": {
"sort_key": "t1.a, t1.b",
Expand Down Expand Up @@ -4933,6 +4940,7 @@ EXPLAIN
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"having_condition": "c < 300 and c < 200",
"filesort": {
"sort_key": "t1.b",
Expand Down Expand Up @@ -5130,6 +5138,7 @@ EXPLAIN
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"having_condition": "c < 300",
"filesort": {
"sort_key": "t1.b",
Expand Down Expand Up @@ -5234,6 +5243,7 @@ EXPLAIN
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"having_condition": "c < 300 and c > 200",
"filesort": {
"sort_key": "t1.a, t1.b",
Expand All @@ -5252,6 +5262,7 @@ EXPLAIN
{
"query_block": {
"select_id": 4,
"operation": "UNION",
"having_condition": "c < 707 and c > 200",
"filesort": {
"sort_key": "t1.a, t1.b",
Expand Down Expand Up @@ -5395,6 +5406,7 @@ EXPLAIN
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"table": {
"table_name": "t1",
"access_type": "ALL",
Expand Down Expand Up @@ -5512,6 +5524,7 @@ EXPLAIN
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"table": {
"table_name": "t1",
"access_type": "ALL",
Expand Down Expand Up @@ -5597,6 +5610,7 @@ EXPLAIN
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"table": {
"table_name": "t1",
"access_type": "ALL",
Expand Down Expand Up @@ -5685,6 +5699,7 @@ EXPLAIN
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"table": {
"table_name": "t1",
"access_type": "ALL",
Expand Down Expand Up @@ -5792,6 +5807,7 @@ EXPLAIN
{
"query_block": {
"select_id": 3,
"operation": "UNION",
"table": {
"table_name": "t1",
"access_type": "ALL",
Expand Down Expand Up @@ -6996,7 +7012,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 100.00 Using where
3 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00
Warnings:
Note 1003 select `sq1`.`f` AS `f` from (select min(`test`.`t1`.`i`) AS `f` from `test`.`t1` having `f` = 8) `sq1` where `sq1`.`f` = 8
Note 1003 /* select#1 */ select `sq1`.`f` AS `f` from (/* select#3 */ select min(`test`.`t1`.`i`) AS `f` from `test`.`t1` having `f` = 8) `sq1` where `sq1`.`f` = 8
SELECT *
FROM ( SELECT * FROM ( SELECT MIN(i) as f FROM t1 ) sq1 ) AS sq2
WHERE f = 8;
Expand Down

0 comments on commit 05d3c3d

Please sign in to comment.