summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Widenius <monty@mariadb.org>2022-08-21 05:53:54 +0300
committerSergei Petrunia <sergey@mariadb.com>2022-09-09 21:00:43 +0300
commitcc6cd19fe532088f9ceb618e6e4a06d0a6efc95e (patch)
tree686fb8ed58b70660d61a6c43140575ae24267dce
parent3763056dcc21306a0dbfe8878d80bf2ca63645eb (diff)
downloadmariadb-git-10.11-psergey-sel-v1.tar.gz
Added optimizer_costs.h which includes all optimizer costsbb-10.11-selectivity-v110.11-psergey-sel-v1
This makes it easier to see how costs changes over commits
-rw-r--r--sql/CMakeLists.txt1
-rw-r--r--sql/handler.h1
-rw-r--r--sql/optimizer_costs.h70
-rw-r--r--sql/sql_const.h50
4 files changed, 72 insertions, 50 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index 4c52bc2858d..e4063edb747 100644
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -174,6 +174,7 @@ SET (SQL_SOURCE
sql_tvc.cc sql_tvc.h
opt_split.cc
rowid_filter.cc rowid_filter.h
+ optimizer_costs.h
opt_trace.cc
table_cache.cc encryption.cc temporary_tables.cc
json_table.cc
diff --git a/sql/handler.h b/sql/handler.h
index 09433a6a90a..be2e39eeaed 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -26,6 +26,7 @@
#endif
#include "sql_const.h"
+#include "optimizer_costs.h"
#include "sql_basic_types.h"
#include "mysqld.h" /* server_id */
#include "sql_plugin.h" /* plugin_ref, st_plugin_int, plugin */
diff --git a/sql/optimizer_costs.h b/sql/optimizer_costs.h
new file mode 100644
index 00000000000..574c0116c54
--- /dev/null
+++ b/sql/optimizer_costs.h
@@ -0,0 +1,70 @@
+#ifndef OPTIMIZER_COSTS_INCLUDED
+#define OPTIMIZER_COSTS_INCLUDED
+/*
+ Copyright (c) 2022, MariaDB AB
+
+ 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 the Free Software Foundation; version 2 of
+ the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
+*/
+
+/* This file includes costs variables used by the optimizer */
+
+/**
+ The following is used to decide if MySQL should use table scanning
+ instead of reading with keys. The number says how many evaluation of the
+ WHERE clause is comparable to reading one extra row from a table.
+*/
+#define TIME_FOR_COMPARE 5.0 // 5 WHERE compares == one read
+#define TIME_FOR_COMPARE_IDX 20.0
+
+#define IDX_BLOCK_COPY_COST ((double) 1 / TIME_FOR_COMPARE)
+#define IDX_LOOKUP_COST ((double) 1 / 8)
+#define MULTI_RANGE_READ_SETUP_COST (IDX_BLOCK_COPY_COST/10)
+
+/**
+ Number of comparisons of table rowids equivalent to reading one row from a
+ table.
+*/
+#define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*100)
+
+/* cost1 is better that cost2 only if cost1 + COST_EPS < cost2 */
+#define COST_EPS 0.001
+
+/*
+ For sequential disk seeks the cost formula is:
+ DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip
+
+ The cost of average seek
+ DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0.
+*/
+#define DISK_SEEK_BASE_COST ((double)0.9)
+
+#define BLOCKS_IN_AVG_SEEK 128
+
+#define DISK_SEEK_PROP_COST ((double)0.1/BLOCKS_IN_AVG_SEEK)
+
+/*
+ Subquery materialization-related constants
+*/
+#define HEAP_TEMPTABLE_LOOKUP_COST 0.05
+#define DISK_TEMPTABLE_LOOKUP_COST 1.0
+#define SORT_INDEX_CMP_COST 0.02
+
+#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)
+
+#endif /* OPTIMIZER_COSTS_INCLUDED */
diff --git a/sql/sql_const.h b/sql/sql_const.h
index bcc556e61f9..40478ed3f94 100644
--- a/sql/sql_const.h
+++ b/sql/sql_const.h
@@ -200,62 +200,12 @@
#define MIN_ROWS_TO_USE_BULK_INSERT 100
/**
- The following is used to decide if MySQL should use table scanning
- instead of reading with keys. The number says how many evaluation of the
- WHERE clause is comparable to reading one extra row from a table.
-*/
-#define TIME_FOR_COMPARE 5.0 // 5 WHERE compares == one read
-#define TIME_FOR_COMPARE_IDX 20.0
-
-#define IDX_BLOCK_COPY_COST ((double) 1 / TIME_FOR_COMPARE)
-#define IDX_LOOKUP_COST ((double) 1 / 8)
-#define MULTI_RANGE_READ_SETUP_COST (IDX_BLOCK_COPY_COST/10)
-
-/**
- Number of comparisons of table rowids equivalent to reading one row from a
- table.
-*/
-#define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*100)
-
-/* cost1 is better that cost2 only if cost1 + COST_EPS < cost2 */
-#define COST_EPS 0.001
-
-/*
- For sequential disk seeks the cost formula is:
- DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip
-
- The cost of average seek
- DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0.
-*/
-#define DISK_SEEK_BASE_COST ((double)0.9)
-
-#define BLOCKS_IN_AVG_SEEK 128
-
-#define DISK_SEEK_PROP_COST ((double)0.1/BLOCKS_IN_AVG_SEEK)
-
-
-/**
Number of rows in a reference table when refereed through a not unique key.
This value is only used when we don't know anything about the key
distribution.
*/
#define MATCHING_ROWS_IN_OTHER_TABLE 10
-/*
- Subquery materialization-related constants
-*/
-#define HEAP_TEMPTABLE_LOOKUP_COST 0.05
-#define DISK_TEMPTABLE_LOOKUP_COST 1.0
-#define SORT_INDEX_CMP_COST 0.02
-
-
-#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). */