Commit 792c67ff authored by Sergey Petrunya's avatar Sergey Petrunya

MWL#90: Address review feedback part #1

parent 125bfa2c
...@@ -1532,12 +1532,6 @@ INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2); ...@@ -1532,12 +1532,6 @@ INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
--echo # MariaDB note:
--echo # This will show 2 for table which has 5 rows.
--echo # This is because the access method employed is actually range access
--echo # which scans 2 records (yes, EXPLAIN displays it incorrectly).
--echo # our correct printing is an artifact of changing in select_describe()
--echo # from printing table->starts.records() to tab->records.
EXPLAIN EXPLAIN
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
...@@ -1551,7 +1545,6 @@ INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2); ...@@ -1551,7 +1545,6 @@ INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
--echo # See above "MariaDB note"
EXPLAIN EXPLAIN
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
...@@ -1566,7 +1559,6 @@ INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2); ...@@ -1566,7 +1559,6 @@ INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
--echo # See above "MariaDB note"
EXPLAIN EXPLAIN
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
......
...@@ -1735,12 +1735,6 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1) ...@@ -1735,12 +1735,6 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1 1
1 1
# MariaDB note:
# This will show 2 for table which has 5 rows.
# This is because the access method employed is actually range access
# which scans 2 records (yes, EXPLAIN displays it incorrectly).
# our correct printing is an artifact of changing in select_describe()
# from printing table->starts.records() to tab->records.
EXPLAIN EXPLAIN
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
...@@ -1755,7 +1749,6 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1) ...@@ -1755,7 +1749,6 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1 1
1 1
# See above "MariaDB note"
EXPLAIN EXPLAIN
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
...@@ -1771,7 +1764,6 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1) ...@@ -1771,7 +1764,6 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1 1
1 1
# See above "MariaDB note"
EXPLAIN EXPLAIN
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
......
...@@ -1735,12 +1735,6 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1) ...@@ -1735,12 +1735,6 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1 1
1 1
# MariaDB note:
# This will show 2 for table which has 5 rows.
# This is because the access method employed is actually range access
# which scans 2 records (yes, EXPLAIN displays it incorrectly).
# our correct printing is an artifact of changing in select_describe()
# from printing table->starts.records() to tab->records.
EXPLAIN EXPLAIN
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
...@@ -1755,7 +1749,6 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1) ...@@ -1755,7 +1749,6 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1 1
1 1
# See above "MariaDB note"
EXPLAIN EXPLAIN
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
...@@ -1771,7 +1764,6 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1) ...@@ -1771,7 +1764,6 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1 1
1 1
# See above "MariaDB note"
EXPLAIN EXPLAIN
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x; FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
......
...@@ -1022,7 +1022,7 @@ Item_in_subselect::Item_in_subselect(Item * left_exp, ...@@ -1022,7 +1022,7 @@ Item_in_subselect::Item_in_subselect(Item * left_exp,
st_select_lex *select_lex): st_select_lex *select_lex):
Item_exists_subselect(), left_expr_cache(0), first_execution(TRUE), Item_exists_subselect(), left_expr_cache(0), first_execution(TRUE),
is_constant(FALSE), optimizer(0), pushed_cond_guards(NULL), is_constant(FALSE), optimizer(0), pushed_cond_guards(NULL),
exec_method(NOT_TRANSFORMED), upper_item(0) exec_method(NOT_TRANSFORMED), is_flattenable_semijoin(FALSE), upper_item(0)
{ {
DBUG_ENTER("Item_in_subselect::Item_in_subselect"); DBUG_ENTER("Item_in_subselect::Item_in_subselect");
left_expr= left_exp; left_expr= left_exp;
...@@ -4080,7 +4080,7 @@ void subselect_hash_sj_engine::cleanup() ...@@ -4080,7 +4080,7 @@ void subselect_hash_sj_engine::cleanup()
int subselect_hash_sj_engine::optimize() int subselect_hash_sj_engine::optimize()
{ {
int res= 0; int res;
SELECT_LEX *save_select= thd->lex->current_select; SELECT_LEX *save_select= thd->lex->current_select;
thd->lex->current_select= materialize_join->select_lex; thd->lex->current_select= materialize_join->select_lex;
res= materialize_join->optimize(); res= materialize_join->optimize();
......
...@@ -406,11 +406,6 @@ public: ...@@ -406,11 +406,6 @@ public:
*/ */
bool is_flattenable_semijoin; bool is_flattenable_semijoin;
/*
Cost to populate the temporary table (set on if-needed basis).
*/
//double startup_cost;
bool *get_cond_guard(int i) bool *get_cond_guard(int i)
{ {
return pushed_cond_guards ? pushed_cond_guards + i : NULL; return pushed_cond_guards ? pushed_cond_guards + i : NULL;
......
...@@ -650,8 +650,6 @@ public: ...@@ -650,8 +650,6 @@ public:
buff= 0; buff= 0;
} }
// JOIN_TAB *get_next_table(JOIN_TAB *tab);
friend class JOIN_CACHE_HASHED; friend class JOIN_CACHE_HASHED;
friend class JOIN_CACHE_BNL; friend class JOIN_CACHE_BNL;
friend class JOIN_CACHE_BKA; friend class JOIN_CACHE_BKA;
......
...@@ -242,9 +242,6 @@ static uint make_join_orderinfo(JOIN *join); ...@@ -242,9 +242,6 @@ static uint make_join_orderinfo(JOIN *join);
Item_equal *find_item_equal(COND_EQUAL *cond_equal, Field *field, Item_equal *find_item_equal(COND_EQUAL *cond_equal, Field *field,
bool *inherited_fl); bool *inherited_fl);
JOIN_TAB *first_linear_tab(JOIN *join, bool after_const_tables);
JOIN_TAB *next_linear_tab(JOIN* join, JOIN_TAB* tab, bool include_bush_roots);
/** /**
This handles SELECT with and without UNION. This handles SELECT with and without UNION.
*/ */
...@@ -8569,6 +8566,12 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after) ...@@ -8569,6 +8566,12 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
tab->sorted= sorted; tab->sorted= sorted;
sorted= 0; // only first must be sorted sorted= 0; // only first must be sorted
/*
We should not set tab->next_select for the last table in the
SMJ-nest, as setup_sj_materialization() has already set it to
end_sj_materialize.
*/
if (!(tab->bush_root_tab && if (!(tab->bush_root_tab &&
tab->bush_root_tab->bush_children->end == tab + 1)) tab->bush_root_tab->bush_children->end == tab + 1))
{ {
...@@ -12910,7 +12913,6 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -12910,7 +12913,6 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
i < field_count; i < field_count;
i++, reg_field++, key_part_info++) i++, reg_field++, key_part_info++)
{ {
key_part_info->null_bit=0;
key_part_info->field= *reg_field; key_part_info->field= *reg_field;
(*reg_field)->flags |= PART_KEY_FLAG; (*reg_field)->flags |= PART_KEY_FLAG;
if (key_part_info == keyinfo->key_part) if (key_part_info == keyinfo->key_part)
......
...@@ -616,7 +616,6 @@ inline bool sj_is_materialize_strategy(uint strategy) ...@@ -616,7 +616,6 @@ inline bool sj_is_materialize_strategy(uint strategy)
return strategy >= SJ_OPT_MATERIALIZE; return strategy >= SJ_OPT_MATERIALIZE;
} }
class JOIN_TAB_RANGE: public Sql_alloc class JOIN_TAB_RANGE: public Sql_alloc
{ {
public: public:
...@@ -1050,6 +1049,9 @@ private: ...@@ -1050,6 +1049,9 @@ private:
}; };
JOIN_TAB *first_linear_tab(JOIN *join, bool after_const_tables);
JOIN_TAB *next_linear_tab(JOIN* join, JOIN_TAB* tab, bool include_bush_roots);
typedef struct st_select_check { typedef struct st_select_check {
uint const_ref,reg_ref; uint const_ref,reg_ref;
} SELECT_CHECK; } SELECT_CHECK;
......
...@@ -6584,9 +6584,6 @@ int make_schema_select(THD *thd, SELECT_LEX *sel, ...@@ -6584,9 +6584,6 @@ int make_schema_select(THD *thd, SELECT_LEX *sel,
} }
JOIN_TAB *first_linear_tab(JOIN *join, bool after_const_tables);
JOIN_TAB *next_linear_tab(JOIN* join, JOIN_TAB* tab, bool include_bush_roots);
/* /*
Fill temporary schema tables before SELECT Fill temporary schema tables before SELECT
......
...@@ -5335,6 +5335,13 @@ bool st_table::is_children_attached(void) ...@@ -5335,6 +5335,13 @@ bool st_table::is_children_attached(void)
} }
/*
Return TRUE if the table is filled at execution phase
(and so, the optimizer must not do anything that depends on the contents of
the table, like range analysis or constant table detection)
*/
bool st_table::is_filled_at_execution() bool st_table::is_filled_at_execution()
{ {
return test(pos_in_table_list->jtbm_subselect); return test(pos_in_table_list->jtbm_subselect);
......
...@@ -968,9 +968,9 @@ struct st_table { ...@@ -968,9 +968,9 @@ struct st_table {
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/* /*
If TRUE, the table is filled at execution phase (and so, the optimizer Returns TRUE if the table is filled at execution phase (and so, the
should not do things like range analysis or constant table detection on optimizer must not do anything that depends on the contents of the table,
it). like range analysis or constant table detection)
*/ */
bool is_filled_at_execution(); bool is_filled_at_execution();
inline void disable_keyread() inline void disable_keyread()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment