summaryrefslogtreecommitdiff
path: root/sql/sql_explain.h
Commit message (Collapse)AuthorAgeFilesLines
* Merge 10.11 into 11.0Sergei Petrunia2023-04-171-2/+15
|\
| * Merge 10.10 into 10.11Marko Mäkelä2023-04-141-3/+18
| |\
| | * Merge 10.8 into 10.9Marko Mäkelä2023-04-141-3/+18
| | |\
| | | * Merge 10.6 into 10.8Marko Mäkelä2023-04-121-3/+18
| | | |\
| | | | * Merge 10.5 into 10.6Marko Mäkelä2023-04-111-1/+1
| | | | |\
| | | | | * Merge remote-tracking branch '10.4' into 10.5Oleksandr Byelkin2023-03-311-1/+1
| | | | | |\
| | | | | | * MDEV-30539 EXPLAIN EXTENDED: no message with queries for DML statementsIgor Babaev2023-03-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | EXPLAIN EXTENDED for an UPDATE/DELETE/INSERT/REPLACE statement did not produce the warning containing the text representation of the query obtained after the optimization phase. Such warning was produced for SELECT statements, but not for DML statements. The patch fixes this defect of EXPLAIN EXTENDED for DML statements.
| | | | * | | MDEV-30972: ANALYZE FORMAT=JSON: some time is unaccounted-for in BNL-H joinSergei Petrunia2023-04-041-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After MDEV-30830 has added block-nl-join.r_unpack_time_ms, it became apparent that there is some unaccounted-for time in BNL join operation, namely the time that is spent after unpacking the join buffer record. Fix this by adding a Gap_time_tracker to track the time that is spent after unpacking the join buffer record and before any next time tracking. The collected time is printed in block-nl-join.r_other_time_ms. Reviewed by: Monty <monty@mariadb.org>
| | | | * | | ANALYZE FORMAT=JSON: Backport block-nl-join.r_unpack_time_ms from 11.0 +fix ↵Sergei Petrunia2023-04-041-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MDEV-30830. Also fix it to work with hashed join (MDEV-30830). Reviewed by: Monty <monty@mariadb.org>
| | | | * | | MDEV-30806: ANALYZE FORMAT=JSON: better support for BNL and BNL-H joinsSergei Petrunia2023-03-311-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In block-nl-join, add: - r_loops - this shows how many incoming record combinations this query plan node had. - r_effective_rows - this shows the average number of matching rows that this table had for each incoming record combination. This is comparable with r_rows in non-blocked access methods. For BNL-joins, it is always equal to $.table.r_rows * $.table.r_filtered For BNL-H joins the value cannot be computed from other values Reviewed by: Monty <monty@mariadb.org>
* | | | | | | Merge 10.11 into 11.0Marko Mäkelä2023-02-161-2/+2
|\ \ \ \ \ \ \ | |/ / / / / /
| * | | | | | Merge 10.10 into 10.11Marko Mäkelä2023-02-161-2/+2
| |\ \ \ \ \ \ | | |/ / / / /
| | * | | | | Merge 10.8 into 10.9Marko Mäkelä2023-02-161-2/+2
| | |\ \ \ \ \ | | | |/ / / /
| | | * | | | Merge 10.6 into 10.8Marko Mäkelä2023-02-101-2/+2
| | | |\ \ \ \ | | | | |/ / /
| | | | * | | Merge 10.5 into 10.6Marko Mäkelä2023-02-101-2/+2
| | | | |\ \ \ | | | | | |/ /
| | | | | * | Merge 10.4 into 10.5Marko Mäkelä2023-02-101-2/+2
| | | | | |\ \ | | | | | | |/
| | | | | | * Apply clang-tidy to remove empty constructors / destructorsVicențiu Ciorbaru2023-02-091-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch is the result of running run-clang-tidy -fix -header-filter=.* -checks='-*,modernize-use-equals-default' . Code style changes have been done on top. The result of this change leads to the following improvements: 1. Binary size reduction. * For a -DBUILD_CONFIG=mysql_release build, the binary size is reduced by ~400kb. * A raw -DCMAKE_BUILD_TYPE=Release reduces the binary size by ~1.4kb. 2. Compiler can better understand the intent of the code, thus it leads to more optimization possibilities. Additionally it enabled detecting unused variables that had an empty default constructor but not marked so explicitly. Particular change required following this patch in sql/opt_range.cc result_keys, an unused template class Bitmap now correctly issues unused variable warnings. Setting Bitmap template class constructor to default allows the compiler to identify that there are no side-effects when instantiating the class. Previously the compiler could not issue the warning as it assumed Bitmap class (being a template) would not be performing a NO-OP for its default constructor. This prevented the "unused variable warning".
* | | | | | | MDEV-30032: EXPLAIN FORMAT=JSON output: part #2: print 'loops'.Sergei Petrunia2023-02-031-0/+3
| | | | | | |
* | | | | | | MDEV-30032: EXPLAIN FORMAT=JSON output: print costsSergei Petrunia2023-02-031-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Basic printout for join and table execution costs.
* | | | | | | Changing all cost calculation to be given in millisecondsMonty2023-02-021-1/+3
|/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This makes it easier to compare different costs and also allows the optimizer to optimizer different storage engines more reliably. - Added tests/check_costs.pl, a tool to verify optimizer cost calculations. - Most engine costs has been found with this program. All steps to calculate the new costs are documented in Docs/optimizer_costs.txt - User optimizer_cost variables are given in microseconds (as individual costs can be very small). Internally they are stored in ms. - Changed DISK_READ_COST (was DISK_SEEK_BASE_COST) from a hard disk cost (9 ms) to common SSD cost (400MB/sec). - Removed cost calculations for hard disks (rotation etc). - Changed the following handler functions to return IO_AND_CPU_COST. This makes it easy to apply different cost modifiers in ha_..time() functions for io and cpu costs. - scan_time() - rnd_pos_time() & rnd_pos_call_time() - keyread_time() - Enhanched keyread_time() to calculate the full cost of reading of a set of keys with a given number of ranges and optional number of blocks that need to be accessed. - Removed read_time() as keyread_time() + rnd_pos_time() can do the same thing and more. - Tuned cost for: heap, myisam, Aria, InnoDB, archive and MyRocks. Used heap table costs for json_table. The rest are using default engine costs. - Added the following new optimizer variables: - optimizer_disk_read_ratio - optimizer_disk_read_cost - optimizer_key_lookup_cost - optimizer_row_lookup_cost - optimizer_row_next_find_cost - optimizer_scan_cost - Moved all engine specific cost to OPTIMIZER_COSTS structure. - Changed costs to use 'records_out' instead of 'records_read' when recalculating costs. - Split optimizer_costs.h to optimizer_costs.h and optimizer_defaults.h. This allows one to change costs without having to compile a lot of files. - Updated costs for filter lookup. - Use a better cost estimate in best_extension_by_limited_search() for the sorting cost. - Fixed previous issues with 'filtered' explain column as we are now using 'records_out' (min rows seen for table) to calculate filtering. This greatly simplifies the filtering code in JOIN_TAB::save_explain_data(). This change caused a lot of queries to be optimized differently than before, which exposed different issues in the optimizer that needs to be fixed. These fixes are in the following commits. To not have to change the same test case over and over again, the changes in the test cases are done in a single commit after all the critical change sets are done. InnoDB changes: - Updated InnoDB to not divide big range cost with 2. - Added cost for InnoDB (innobase_update_optimizer_costs()). - Don't mark clustered primary key with HA_KEYREAD_ONLY. This will prevent that the optimizer is trying to use index-only scans on the clustered key. - Disabled ha_innobase::scan_time() and ha_innobase::read_time() and ha_innobase::rnd_pos_time() as the default engine cost functions now works good for InnoDB. Other things: - Added --show-query-costs (\Q) option to mysql.cc to show the query cost after each query (good when working with query costs). - Extended my_getopt with GET_ADJUSTED_VALUE which allows one to adjust the value that user is given. This is used to change cost from microseconds (user input) to milliseconds (what the server is internally using). - Added include/my_tracker.h ; Useful include file to quickly test costs of a function. - Use handler::set_table() in all places instead of 'table= arg'. - Added SHOW_OPTIMIZER_COSTS to sys variables. These are input and shown in microseconds for the user but stored as milliseconds. This is to make the numbers easier to read for the user (less pre-zeros). Implemented in 'Sys_var_optimizer_cost' class. - In test_quick_select() do not use index scans if 'no_keyread' is set for the table. This is what we do in other places of the server. - Added THD parameter to Unique::get_use_cost() and check_index_intersect_extension() and similar functions to be able to provide costs to called functions. - Changed 'records' to 'rows' in optimizer_trace. - Write more information to optimizer_trace. - Added INDEX_BLOCK_FILL_FACTOR_MUL (4) and INDEX_BLOCK_FILL_FACTOR_DIV (3) to calculate usage space of keys in b-trees. (Before we used numeric constants). - Removed code that assumed that b-trees has similar costs as binary trees. Replaced with engine calls that returns the cost. - Added Bitmap::find_first_bit() - Added timings to join_cache for ANALYZE table (patch by Sergei Petrunia). - Added records_init and records_after_filter to POSITION to remember more of what best_access_patch() calculates. - table_after_join_selectivity() changed to recalculate 'records_out' based on the new fields from best_access_patch() Bug fixes: - Some queries did not update last_query_cost (was 0). Fixed by moving setting thd->...last_query_cost in JOIN::optimize(). - Write '0' as number of rows for const tables with a matching row. Some internals: - Engine cost are stored in OPTIMIZER_COSTS structure. When a handlerton is created, we also created a new cost variable for the handlerton. We also create a new variable if the user changes a optimizer cost for a not yet loaded handlerton either with command line arguments or with SET @@global.engine.optimizer_cost_variable=xx. - There are 3 global OPTIMIZER_COSTS variables: default_optimizer_costs The default costs + changes from the command line without an engine specifier. heap_optimizer_costs Heap table costs, used for temporary tables tmp_table_optimizer_costs The cost for the default on disk internal temporary table (MyISAM or Aria) - The engine cost for a table is stored in table_share. To speed up accesses the handler has a pointer to this. The cost is copied to the table on first access. If one wants to change the cost one must first update the global engine cost and then do a FLUSH TABLES. This was done to be able to access the costs for an open table without any locks. - When a handlerton is created, the cost are updated the following way: See sql/keycaches.cc for details: - Use 'default_optimizer_costs' as a base - Call hton->update_optimizer_costs() to override with the engines default costs. - Override the costs that the user has specified for the engine. - One handler open, copy the engine cost from handlerton to TABLE_SHARE. - Call handler::update_optimizer_costs() to allow the engine to update cost for this particular table. - There are two costs stored in THD. These are copied to the handler when the table is used in a query: - optimizer_where_cost - optimizer_scan_setup_cost - Simply code in best_access_path() by storing all cost result in a structure. (Idea/Suggestion by Igor)
* | | | | | MDEV-28926 Add time spent on query optimizer to JSON ANALYZE (#2193)Luis Eduardo Oliveira Lizardo2022-10-261-0/+6
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add query optimizer timer to ANALYZE FORMAT=JSON * Adapt tests and results * Change logic to always close the writer after printing query blocks
* | | | | Fix comment.Sergei Petrunia2022-04-291-1/+1
| | | | |
* | | | | MDEV-28201: Server crashes upon SHOW ANALYZE/EXPLAIN FORMAT=JSONSergei Petrunia2022-04-291-41/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Describe the lifetime of EXPLAIN data structures in sql_explain.h:ExplainDataStructureLifetime. - Make Item_field::set_field() call set_refers_to_temp_table() when it refers to a temp. table. - Introduce QT_DONT_ACCESS_TMP_TABLES flag for Item::print. It directs Item_field::print to not try access its the temp table. - Introduce Explain_query::notify_tables_are_closed() and call it right before the query closes its tables. - Make Explain data stuctures' print_explain_json() methods accept "no_tmp_tbl" parameter which means pass QT_DONT_ACCESS_TMP_TABLES when printing items. - Make Show_explain_request::call_in_target_thread() not call set_current_thd(). This wasn't needed as the code inside lex->print_explain() uses output->thd anyway. output->thd refers to the SHOW command's THD object.
* | | | | MDEV-28124 Server crashes in Explain_aggr_filesort::print_json_membersOleg Smirnov2022-04-291-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | SHOW EXPLAIN/ANALYZE FORMAT=JSON tries to access items that have already been freed by a call to free_items() during THD::cleanup_after_query(). The solution is to disallow APC calls including SHOW EXPLAIN/ANALYZE just before the call to free_items().
* | | | | MDEV-27021 Add explicit indication of SHOW EXPLAIN/ANALYZE.Oleg Smirnov2022-04-291-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. Add explicit indication that the output is produced by SHOW EXPLAIN/ANALYZE FORMAT=JSON command. 2. Remove useless "r_total_time_ms" field from SHOW ANALYZE FORMAT=JSON output when there is no timed statistics gathered. 3. Add "r_query_time_in_progress_ms" to the output of SHOW ANALYZE FORMAT=JSON.
* | | | | MDEV-10000 Add EXPLAIN [FORMAT=JSON] FOR CONNECTION syntax supportOleg Smirnov2022-04-291-1/+1
|/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | EXPLAIN FOR CONNECTION is a MySQL-compatible syntax for SHOW EXPLAIN. This commit also adds support for FORMAT=JSON to SHOW EXPLAIN, so the possible options to get JSON-formatted output are: - SHOW EXPLAIN FORMAT=JSON FOR $con - EXPLAIN FORMAT=JSON FOR CONNECTION $con
* | | | MDEV-27036: re-enable my_json_writer-t unit testbb-10.8-MDEV-27036-enable-unittestSergei Krivonos2021-12-151-1/+0
| | | |
* | | | Revert "MDEV-27036: re-enable my_json_writer-t unit test"Sergei Golubchik2021-12-071-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 2d21917e7db2db0900671aac2e29f49e4ff2acd7. No explainations, lots of code moved, wrong cmake changes
* | | | MDEV-27036: re-enable my_json_writer-t unit testSergei Krivonos2021-12-041-0/+2
|/ / /
* | | Merge 10.5 into 10.6Marko Mäkelä2021-10-131-0/+2
|\ \ \ | |/ / | | | | | | | | | | | | | | | The changes to galera.galear_var_replicate_myisam_on in commit d9b933bec6061758c5d7b34f55afcae32a85c110 are omitted due to conflicts with commit 27d66d644cf2ebe9201e0362f2050036cce2908a.
| * | Merge 10.4 into 10.5Marko Mäkelä2021-10-131-0/+2
| |\ \ | | |/
| | * Merge 10.3 into 10.4Marko Mäkelä2021-10-131-0/+2
| | |\
| | | * Merge 10.2 into 10.3Marko Mäkelä2021-10-131-0/+2
| | | |\
| | | | * Make Explain_node::children protectedSergei Petrunia2021-10-081-0/+2
| | | | |
* | | | | MDEV-17399 Add support for JSON_TABLE.Alexey Botchkov2021-04-211-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | The specific table handler for the table functions was introduced, and used to implement JSON_TABLE.
* | | | | Cleanup: fake_select_lex->select_number=FAKE_SELECT_LEX_ID, not [U]INT_MAXSergei Petrunia2021-04-171-8/+8
|/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | SELECT_LEX objects that are "fake_select_lex" (i.e read UNION output) used both INT_MAX and UINT_MAX as select_number. - mysql_explain_union() assigned UINT_MAX - st_select_lex_unit::add_fake_select_lex assigned INT_MAX This didn't matter initially (before EXPLAIN FORMAT=JSON), because the code had no checks for this value. EXPLAIN FORMAT=JSON and later other features did introduce checks for select_number values. The check had to check for two constants and looked really confusing. This patch joins the two constants into one - FAKE_SELECT_LEX_ID.
* | | | Merge 10.4 into 10.5Marko Mäkelä2020-05-131-0/+2
|\ \ \ \ | |/ / /
| * | | Merge 10.3 into 10.4Marko Mäkelä2020-05-131-0/+2
| |\ \ \ | | |/ /
| | * | MDEV-17568: LATERAL DERIVED is not clearly visible in EXPLAIN FORMAT=JSONSergei Petrunia2020-05-061-0/+2
| | | | | | | | | | | | | | | | Make LATERAL DERIVED tables visible in EXPLAIN FORMAT=JSON output.
* | | | perfschema memory related instrumentation changesSergei Golubchik2020-03-101-1/+1
| | | |
* | | | MDEV-20854: ANALYZE for statements: not clear where the time is spentSergei Petrunia2019-11-121-0/+2
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Count the "gap" time between table accesses and display it as r_other_time_ms in the "table" element. * The advantage of this approach is that it doesn't add any new my_timer_cycles() calls. * The disadvantage is that the definition of what is done during "other time" is not that clear: it includes checking the WHERE (for this table), constructing index lookup tuple (for the next table) writing to GROUP BY temporary table (as we dont account for that time separately [yet], etc)
* | | Merge 10.3 into 10.4Marko Mäkelä2019-06-121-0/+1
|\ \ \ | |/ /
| * | Merge 10.2 into 10.3Marko Mäkelä2019-06-111-0/+1
| |\ \ | | |/
| | * MDEV-19714: JOIN::pseudo_bits_cond is not visible in EXPLAIN FORMAT=JSONbb-10.2-mdev19714Sergei Petrunia2019-06-081-0/+1
| | | | | | | | | | | | Make it visible
* | | Merge branch '10.3' into 10.4Oleksandr Byelkin2019-05-191-1/+1
|\ \ \ | |/ /
| * | Merge 10.2 into 10.3Marko Mäkelä2019-05-141-1/+1
| |\ \ | | |/
| | * Merge 10.1 into 10.2Marko Mäkelä2019-05-131-1/+1
| | |\
| | | * Merge branch '5.5' into 10.1Vicențiu Ciorbaru2019-05-111-1/+1
| | | |
* | | | Merge branch '10.4' into bb-10.4-mdev16188Igor Babaev2019-02-141-0/+2
|\ \ \ \
| * | | | MDEV-17096 Pushdown of simple derived tables to storage enginesIgor Babaev2019-02-061-0/+2
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | MDEV-17631 select_handler for a full query pushdown Interfaces + Proof of Concept for federatedx with test cases. The interfaces have been developed for integration of ColumnStore engine.