Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
bf8fe324
Commit
bf8fe324
authored
May 28, 2019
by
Marko Mäkelä
Browse files
Options
Browse Files
Download
Plain Diff
Merge 5.5 into 10.1
parents
626f2a1c
0955462d
Changes
12
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
802 additions
and
91 deletions
+802
-91
cmake/cpack_rpm.cmake
cmake/cpack_rpm.cmake
+1
-1
include/my_valgrind.h
include/my_valgrind.h
+8
-0
mysql-test/r/derived_view.result
mysql-test/r/derived_view.result
+401
-0
mysql-test/r/subselect_sj.result
mysql-test/r/subselect_sj.result
+1
-0
mysql-test/r/subselect_sj_jcl6.result
mysql-test/r/subselect_sj_jcl6.result
+1
-0
mysql-test/t/derived_view.test
mysql-test/t/derived_view.test
+260
-0
mysql-test/t/subselect_sj.test
mysql-test/t/subselect_sj.test
+2
-0
mysys/my_alloc.c
mysys/my_alloc.c
+2
-1
sql/opt_subselect.cc
sql/opt_subselect.cc
+43
-30
sql/sql_const.h
sql/sql_const.h
+8
-0
sql/sql_parse.cc
sql/sql_parse.cc
+7
-0
sql/sql_select.cc
sql/sql_select.cc
+68
-59
No files found.
cmake/cpack_rpm.cmake
View file @
bf8fe324
...
...
@@ -37,7 +37,7 @@ IF(CMAKE_VERSION VERSION_LESS "3.6.0")
SET
(
CPACK_PACKAGE_FILE_NAME
"
${
CPACK_RPM_PACKAGE_NAME
}
-
${
VERSION
}
-
${
RPM
}
-
${
CMAKE_SYSTEM_PROCESSOR
}
"
)
ELSE
()
SET
(
CPACK_RPM_FILE_NAME
"RPM-DEFAULT"
)
SET
(
CPACK_RPM_DEBUGINFO_PACKAGE ON
)
SET
(
CPACK_RPM_DEBUGINFO_PACKAGE ON
CACHE INTERNAL
""
)
ENDIF
()
SET
(
CPACK_RPM_PACKAGE_RELEASE
"1%{?dist}"
)
...
...
include/my_valgrind.h
View file @
bf8fe324
...
...
@@ -13,6 +13,9 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
#ifndef MY_VALGRIND_INCLUDED
#define MY_VALGRIND_INCLUDED
/* clang -> gcc */
#ifndef __has_feature
# define __has_feature(x) 0
...
...
@@ -33,6 +36,7 @@
# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
# define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len)
# define MEM_CHECK_DEFINED(a,len) VALGRIND_CHECK_MEM_IS_DEFINED(a,len)
# define REDZONE_SIZE 8
#elif defined(__SANITIZE_ADDRESS__)
# include <sanitizer/asan_interface.h>
/* How to do manual poisoning:
...
...
@@ -41,11 +45,13 @@
# define MEM_NOACCESS(a,len) ASAN_POISON_MEMORY_REGION(a,len)
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
# define MEM_CHECK_DEFINED(a,len) ((void) 0)
# define REDZONE_SIZE 8
#else
# define MEM_UNDEFINED(a,len) ((void) (a), (void) (len))
# define MEM_NOACCESS(a,len) ((void) 0)
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
# define MEM_CHECK_DEFINED(a,len) ((void) 0)
# define REDZONE_SIZE 0
#endif
/* HAVE_VALGRIND */
#ifndef DBUG_OFF
...
...
@@ -55,3 +61,5 @@
#endif
#define TRASH_ALLOC(A,B) do { TRASH_FILL(A,B,0xA5); MEM_UNDEFINED(A,B); } while(0)
#define TRASH_FREE(A,B) do { TRASH_FILL(A,B,0x8F); MEM_NOACCESS(A,B); } while(0)
#endif
/* MY_VALGRIND_INCLUDED */
mysql-test/r/derived_view.result
View file @
bf8fe324
This diff is collapsed.
Click to expand it.
mysql-test/r/subselect_sj.result
View file @
bf8fe324
...
...
@@ -3189,6 +3189,7 @@ drop table t1,t2,t3;
#
# MDEV-18896: IN subquery in WHERE of a table-less query used for INSERT
#
set @@optimizer_switch= @subselect_sj_tmp;
create table t1 (a1 varchar(25));
create table t2 (a2 varchar(25)) ;
insert into t1 select 'xxx' from dual where 'xxx' in (select a2 from t2);
...
...
mysql-test/r/subselect_sj_jcl6.result
View file @
bf8fe324
...
...
@@ -3203,6 +3203,7 @@ drop table t1,t2,t3;
#
# MDEV-18896: IN subquery in WHERE of a table-less query used for INSERT
#
set @@optimizer_switch= @subselect_sj_tmp;
create table t1 (a1 varchar(25));
create table t2 (a2 varchar(25)) ;
insert into t1 select 'xxx' from dual where 'xxx' in (select a2 from t2);
...
...
mysql-test/t/derived_view.test
View file @
bf8fe324
This diff is collapsed.
Click to expand it.
mysql-test/t/subselect_sj.test
View file @
bf8fe324
...
...
@@ -2877,6 +2877,8 @@ drop table t1,t2,t3;
--
echo
# MDEV-18896: IN subquery in WHERE of a table-less query used for INSERT
--
echo
#
set
@@
optimizer_switch
=
@
subselect_sj_tmp
;
create
table
t1
(
a1
varchar
(
25
));
create
table
t2
(
a2
varchar
(
25
))
;
insert
into
t1
select
'xxx'
from
dual
where
'xxx'
in
(
select
a2
from
t2
);
...
...
mysys/my_alloc.c
View file @
bf8fe324
...
...
@@ -217,7 +217,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
DBUG_SET
(
"-d,simulate_out_of_memory"
);
DBUG_RETURN
((
void
*
)
0
);
/* purecov: inspected */
});
length
=
ALIGN_SIZE
(
length
);
length
=
ALIGN_SIZE
(
length
)
+
REDZONE_SIZE
;
if
((
*
(
prev
=
&
mem_root
->
free
))
!=
NULL
)
{
if
((
*
prev
)
->
left
<
length
&&
...
...
@@ -265,6 +265,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
mem_root
->
used
=
next
;
mem_root
->
first_block_usage
=
0
;
}
point
+=
REDZONE_SIZE
;
TRASH_ALLOC
(
point
,
original_length
);
DBUG_PRINT
(
"exit"
,(
"ptr: %p"
,
point
));
DBUG_RETURN
((
void
*
)
point
);
...
...
sql/opt_subselect.cc
View file @
bf8fe324
/*
Copyright (c) 2010, 201
5
, MariaDB
Copyright (c) 2010, 201
9
, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
...
...
@@ -28,6 +28,7 @@
#include <my_global.h>
#include "sql_base.h"
#include "sql_const.h"
#include "sql_select.h"
#include "filesort.h"
#include "opt_subselect.h"
...
...
@@ -522,7 +523,7 @@ bool is_materialization_applicable(THD *thd, Item_in_subselect *in_subs,
if
(
optimizer_flag
(
thd
,
OPTIMIZER_SWITCH_MATERIALIZATION
)
&&
// 0
!
child_select
->
is_part_of_union
()
&&
// 1
parent_unit
->
first_select
()
->
leaf_tables
.
elements
&&
// 2
child_select
->
outer_select
()
->
leaf_tables
.
elements
&&
// 2A
child_select
->
outer_select
()
->
table_list
.
first
&&
// 2A
subquery_types_allow_materialization
(
in_subs
)
&&
(
in_subs
->
is_top_level_item
()
||
//3
optimizer_flag
(
thd
,
...
...
@@ -1383,8 +1384,8 @@ void get_delayed_table_estimates(TABLE *table,
*
startup_cost
=
item
->
jtbm_read_time
;
/* Calculate cost of scanning the temptable */
double
data_size
=
item
->
jtbm_record_count
*
hash_sj_engine
->
tmp_table
->
s
->
reclength
;
double
data_size
=
COST_MULT
(
item
->
jtbm_record_count
,
hash_sj_engine
->
tmp_table
->
s
->
reclength
)
;
/* Do like in handler::read_time */
*
scan_time
=
data_size
/
IO_SIZE
+
2
;
}
...
...
@@ -2467,7 +2468,8 @@ bool optimize_semijoin_nests(JOIN *join, table_map all_table_map)
int
tableno
;
double
rows
=
1.0
;
while
((
tableno
=
tm_it
.
next_bit
())
!=
Table_map_iterator
::
BITMAP_END
)
rows
*=
join
->
map2table
[
tableno
]
->
table
->
quick_condition_rows
;
rows
=
COST_MULT
(
rows
,
join
->
map2table
[
tableno
]
->
table
->
quick_condition_rows
);
sjm
->
rows
=
MY_MIN
(
sjm
->
rows
,
rows
);
}
memcpy
((
uchar
*
)
sjm
->
positions
,
...
...
@@ -2581,7 +2583,7 @@ static uint get_tmp_table_rec_length(Item **p_items, uint elements)
static
double
get_tmp_table_lookup_cost
(
THD
*
thd
,
double
row_count
,
uint
row_size
)
{
if
(
row_count
*
row_size
>
thd
->
variables
.
max_heap_table
_size
)
if
(
row_count
>
thd
->
variables
.
max_heap_table_size
/
(
double
)
row
_size
)
return
(
double
)
DISK_TEMPTABLE_LOOKUP_COST
;
else
return
(
double
)
HEAP_TEMPTABLE_LOOKUP_COST
;
...
...
@@ -2987,8 +2989,11 @@ bool Sj_materialization_picker::check_qep(JOIN *join,
}
double
mat_read_time
=
prefix_cost
.
total_cost
();
mat_read_time
+=
mat_info
->
materialization_cost
.
total_cost
()
+
prefix_rec_count
*
mat_info
->
lookup_cost
.
total_cost
();
mat_read_time
=
COST_ADD
(
mat_read_time
,
COST_ADD
(
mat_info
->
materialization_cost
.
total_cost
(),
COST_MULT
(
prefix_rec_count
,
mat_info
->
lookup_cost
.
total_cost
())));
/*
NOTE: When we pick to use SJM[-Scan] we don't memcpy its POSITION
...
...
@@ -3028,9 +3033,12 @@ bool Sj_materialization_picker::check_qep(JOIN *join,
}
/* Add materialization cost */
prefix_cost
+=
mat_info
->
materialization_cost
.
total_cost
()
+
prefix_rec_count
*
mat_info
->
scan_cost
.
total_cost
();
prefix_rec_count
*=
mat_info
->
rows
;
prefix_cost
=
COST_ADD
(
prefix_cost
,
COST_ADD
(
mat_info
->
materialization_cost
.
total_cost
(),
COST_MULT
(
prefix_rec_count
,
mat_info
->
scan_cost
.
total_cost
())));
prefix_rec_count
=
COST_MULT
(
prefix_rec_count
,
mat_info
->
rows
);
uint
i
;
table_map
rem_tables
=
remaining_tables
;
...
...
@@ -3044,8 +3052,8 @@ bool Sj_materialization_picker::check_qep(JOIN *join,
{
best_access_path
(
join
,
join
->
positions
[
i
].
table
,
rem_tables
,
i
,
disable_jbuf
,
prefix_rec_count
,
&
curpos
,
&
dummy
);
prefix_rec_count
*=
curpos
.
records_read
;
prefix_cost
+=
curpos
.
read_time
;
prefix_rec_count
=
COST_MULT
(
prefix_rec_count
,
curpos
.
records_read
)
;
prefix_cost
=
COST_ADD
(
prefix_cost
,
curpos
.
read_time
)
;
}
*
strategy
=
SJ_OPT_MATERIALIZE_SCAN
;
...
...
@@ -3352,16 +3360,18 @@ bool Duplicate_weedout_picker::check_qep(JOIN *join,
for
(
uint
j
=
first_dupsweedout_table
;
j
<=
idx
;
j
++
)
{
POSITION
*
p
=
join
->
positions
+
j
;
current_fanout
*=
p
->
records_read
;
dups_cost
+=
p
->
read_time
+
current_fanout
/
TIME_FOR_COMPARE
;
current_fanout
=
COST_MULT
(
current_fanout
,
p
->
records_read
);
dups_cost
=
COST_ADD
(
dups_cost
,
COST_ADD
(
p
->
read_time
,
current_fanout
/
TIME_FOR_COMPARE
));
if
(
p
->
table
->
emb_sj_nest
)
{
sj_inner_fanout
*=
p
->
records_read
;
sj_inner_fanout
=
COST_MULT
(
sj_inner_fanout
,
p
->
records_read
)
;
dups_removed_fanout
|=
p
->
table
->
table
->
map
;
}
else
{
sj_outer_fanout
*=
p
->
records_read
;
sj_outer_fanout
=
COST_MULT
(
sj_outer_fanout
,
p
->
records_read
)
;
temptable_rec_size
+=
p
->
table
->
table
->
file
->
ref_length
;
}
}
...
...
@@ -3380,12 +3390,13 @@ bool Duplicate_weedout_picker::check_qep(JOIN *join,
sj_outer_fanout
,
temptable_rec_size
);
double
write_cost
=
join
->
positions
[
first_tab
].
prefix_record_count
*
sj_outer_fanout
*
one_write_cost
;
double
full_lookup_cost
=
join
->
positions
[
first_tab
].
prefix_record_count
*
sj_outer_fanout
*
sj_inner_fanout
*
one_lookup_cost
;
dups_cost
+=
write_cost
+
full_lookup_cost
;
double
write_cost
=
COST_MULT
(
join
->
positions
[
first_tab
].
prefix_record_count
,
sj_outer_fanout
*
one_write_cost
);
double
full_lookup_cost
=
COST_MULT
(
join
->
positions
[
first_tab
].
prefix_record_count
,
COST_MULT
(
sj_outer_fanout
,
sj_inner_fanout
*
one_lookup_cost
));
dups_cost
=
COST_ADD
(
dups_cost
,
COST_ADD
(
write_cost
,
full_lookup_cost
));
*
read_time
=
dups_cost
;
*
record_count
=
prefix_rec_count
*
sj_outer_fanout
;
...
...
@@ -3532,8 +3543,8 @@ static void recalculate_prefix_record_count(JOIN *join, uint start, uint end)
if
(
j
==
join
->
const_tables
)
prefix_count
=
1.0
;
else
prefix_count
=
join
->
best_positions
[
j
-
1
].
prefix_record_count
*
join
->
best_positions
[
j
-
1
].
records_read
;
prefix_count
=
COST_MULT
(
join
->
best_positions
[
j
-
1
].
prefix_record_count
,
join
->
best_positions
[
j
-
1
].
records_read
)
;
join
->
best_positions
[
j
].
prefix_record_count
=
prefix_count
;
}
...
...
@@ -5882,14 +5893,16 @@ bool JOIN::choose_subquery_plan(table_map join_tables)
The cost of executing the subquery and storing its result in an indexed
temporary table.
*/
double
materialization_cost
=
inner_read_time_1
+
write_cost
*
inner_record_count_1
;
double
materialization_cost
=
COST_ADD
(
inner_read_time_1
,
COST_MULT
(
write_cost
,
inner_record_count_1
));
materialize_strategy_cost
=
materialization_cost
+
outer_lookup_keys
*
lookup_cost
;
materialize_strategy_cost
=
COST_ADD
(
materialization_cost
,
COST_MULT
(
outer_lookup_keys
,
lookup_cost
));
/* C.2 Compute the cost of the IN=>EXISTS strategy. */
in_exists_strategy_cost
=
outer_lookup_keys
*
inner_read_time_2
;
in_exists_strategy_cost
=
COST_MULT
(
outer_lookup_keys
,
inner_read_time_2
)
;
/* C.3 Compare the costs and choose the cheaper strategy. */
if
(
materialize_strategy_cost
>=
in_exists_strategy_cost
)
...
...
sql/sql_const.h
View file @
bf8fe324
...
...
@@ -234,6 +234,14 @@
#define HEAP_TEMPTABLE_LOOKUP_COST 0.05
#define DISK_TEMPTABLE_LOOKUP_COST 1.0
#define COST_MAX (DBL_MAX * (1.0 - DBL_EPSILON))
#define COST_ADD(c,d) (COST_MAX - (d) > (c) ? (c) + (d) : COST_MAX)
#define COST_MULT(c,f) (COST_MAX / (f) > (c) ? (c) * (f) : COST_MAX)
#define MY_CHARSET_BIN_MB_MAXLEN 1
/** Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used). */
...
...
sql/sql_parse.cc
View file @
bf8fe324
...
...
@@ -4022,6 +4022,13 @@ mysql_execute_command(THD *thd)
*/
/* Skip first table, which is the table we are inserting in */
TABLE_LIST
*
second_table
=
first_table
->
next_local
;
/*
This is a hack: this leaves select_lex->table_list in an inconsistent
state as 'elements' does not contain number of elements in the list.
Moreover, if second_table == NULL then 'next' becomes invalid.
TODO: fix it by removing the front element (restoring of it should
be done properly as well)
*/
select_lex
->
table_list
.
first
=
second_table
;
select_lex
->
context
.
table_list
=
select_lex
->
context
.
first_name_resolution_table
=
second_table
;
...
...
sql/sql_select.cc
View file @
bf8fe324
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment