- 03 Feb, 2023 26 commits
-
-
Sergei Petrunia authored
Fixes over previous patches: do tracing of attached conditions close to where we generate them. Fix the tracing code to print the right conditions.
-
Rex authored
MDEV-21092,MDEV-21095,MDEV-29997: Optimizer Trace for index condition pushdown, partition pruning, exists-to-in Add Optimizer Tracing for: - Index Condition Pushdown - Partition Pruning - Exists-to-IN optimization
-
Sergei Petrunia authored
Make sure the queries use the intended query plan
-
Sergei Petrunia authored
This seems to confuse windows.
-
Sergei Petrunia authored
-
Monty authored
This was done after discussions with Igor, Sanja and Bar. The main reason for removing the deprication was to ensure that MariaDB is always backward compatible whenever possible. Other things: - Added statistics counters, mainly for the feedback plugin. - INTO OUTFILE - INTO variable - If INTO is using the old syntax (end of query)
-
Monty authored
-
Monty authored
In essence this means that we expect the user query to have at least one matching row in the end. This change will not affect the estimated rows for the plan, but will ensure that the cost for adding a table is not neglected because of record count being too low. The reasons for this is that if we have table combination that together has a very high selectivity then join record_count could become very low (close to 0) This would cause costs for all future tables to be so small that they are irrelevant for the rest of the plan. This has been shown to be the case in some performance benchmarks and in a few mtr tests. There is also still a problem in selectivity calculations as joining two tables in different order causes a different estimation of total rows. This can be seen in selectivity_innodb.test, test 'Q20' where joining nation,supplier is expecting 1.111 rows_out while joining supplier,nation is expecting 0.04 rows_out. The reason for 0.04 is that the optimizer estimates 'supplier' to have 10 matching rows, and joining with nation (eq_ref) has 1 row. However selectivity of n_name = 'UNITED STATES' makes the optimizer things that there will be only 0.04 matching rows. This patch avoids this "too low row count" to affect cost caclulations.
-
Monty authored
- Changed 'WARNING' of type "You need to use --log-bin to make ... work" to 'Note' - Only print startup Notes if log_warnings >= 4
-
Monty authored
-
Monty authored
"select * from information_schema.tables limit 1" was giving the following warning in the log: [ERROR] Invalid (old?) table or database name '#rocksdb'
-
Sergei Petrunia authored
-
Sergei Petrunia authored
Basic printout for join and table execution costs.
-
Monty authored
-
Monty authored
- Simplified test by setting read_time=DBL_MAX at start of loop if FORCE INDEX is used - No need to test for 'group by' as the cost compare should handle it. - Only one test change where index scan was replaced with table scan (correct)
-
Monty authored
- The comment in test_if_skip_sort_order was removed together with a not needed test of 'select'
-
Monty authored
Added override to a few functions in ha_partition.h
-
Monty authored
-
Monty authored
-
Monty authored
In the case one has an old Aria log file that ands with a Aria checkpoint and the server restarts after next recovery, just after created a new Aria log file (of 8K), the Aria recovery code would abort. If one would try to delete all Aria log files after this (but not the aria_control_file), the server would crash during recovery. The problem was that translog_get_last_page_addr() would regard a log file of exactly 8K as illegal and the rest of the code could not handle this case. Another issue was that if there was a crash directly after the log file head was written to the next page, the code in translog_get_next_chunk() would crash. This patch fixes most of the issues, but not all. For Sanja to look at! Things fixed: - Added code to ignore 8K log files. - Removed ASSERT in translog_get_next_chunk() that checks if page only contains the log page header.
-
Monty authored
I spent 4 hours on work and 12 hours of testing to try to find the reason for aria crashing in recovery when starting a new test, in which case the 'data directory' should be a copy of "install.db", but aria_log.00000001 content was not correct. The following changes are mostly done to make it a bit easier to find out more in case of future similar crashes: - Mark last_checkpoint_lsn volatile (safety). - Write checkpoint message to aria_recovery.trace - When compling with DBUG and with HAVE_DBUG_TRANSLOG_SRC, use checksum's for Aria log pages. We cannot have it on by default for DBUG servers yet as there is bugs when changing CRC between restarts. - Added a message to mtr --verbose when copying the data directory. - Removed extra linefeed in Aria recovery message (cleanup)
-
Monty authored
This includes: - cleanup and optimization of filtering and pushdown engine code. - Adjusted costs for rowid filters (based on extensive testing and profiling). This made a small two changes to the handler_rowid_filter_is_active() API: - One should not call it with a zero pointer! - One does not need to call handler_rowid_filter_is_active() for every row anymore. It is enough to check if filter is active by calling it call it during index_init() or when handler::rowid_filter_changed() is called The changes was to avoid unnecessary function calls and checks if pushdown conditions and rowid_filter is not used. Updated costs for rowid_filter_lookup() to be closer to reality. The old cost was based only on rowid_compare_cost. This is now changed to take into account the overhead in checking the rowid. Changed the Range_rowid_filter class to use DYNAMIC_ARRAY directly instead of Dynamic_array<>. This was done to be able to use the new append_dynamic() functions which gives a notable speed improvment compared to the old code. Removing the abstraction also makes the code easier to understand. The cost of filtering is now slightly lower than before, which is reflected in some test cases that is now using rowid filters.
-
Monty authored
This helps with debugging as 'Query: ' in DBUG traces will show something useful, for internal transactions, instead of just "".
-
Sergei Petrunia authored
-
Monty authored
This will speed up using tables that are already zerofilled with aria_chk --zerofill.
-
Sergei Petrunia authored
-
- 02 Feb, 2023 14 commits
-
-
Monty authored
This includes all test changes from "Changing all cost calculation to be given in milliseconds" and forwards. Some of the things that caused changes in the result files: - As part of fixing tests, I added 'echo' to some comments to be able to easier find out where things where wrong. - MATERIALIZED has now a higher cost compared to X than before. Because of this some MATERIALIZED types have changed to DEPENDEND SUBQUERY. - Some test cases that required MATERIALIZED to repeat a bug was changed by adding more rows to force MATERIALIZED to happen. - 'Filtered' in SHOW EXPLAIN has in many case changed from 100.00 to something smaller. This is because now filtered also takes into account the smallest possible ref access and filters, even if they where not used. Another reason for 'Filtered' being smaller is that we now also take into account implicit filtering done for subqueries using FIRSTMATCH. (main.subselect_no_exists_to_in) This is caluculated in best_access_path() and stored in records_out. - Table orders has changed because more accurate costs. - 'index' and 'ALL' for small tables has changed to use 'range' or 'ref' because of optimizer_scan_setup_cost. - index can be changed to 'range' as 'range' optimizer assumes we don't have to read the blocks from disk that range optimizer has already read. This can be confusing in the case where there is no obvious where clause but instead there is a hidden 'key_column > NULL' added by the optimizer. (main.subselect_no_exists_to_in) - Scan on primary clustered key does not report 'Using Index' anymore (It's a table scan, not an index scan). - For derived tables, the number of rows is now 100 instead of 2, which can be seen in EXPLAIN. - More tests have "Using index for group by" as the cost of this optimization is now more correct (lower). - A primary key could be preferred for a normal key, even if it would access more rows, as it's faster to do 1 lokoup and 3 'index_next' on a clustered primary key than one lookup trough a secondary. (main.stat_tables_innodb) Notes: - There was a 4.7% more calls to best_extension_by_limited_search() in the main.greedy_optimizer test. However examining the test results it looked that the plans where slightly better (eq_ref where more chained together) so I assume this is ok. - I have verified a few test cases where there was notable/unexpected changes in the plan and in all cases the new optimizer plans where faster. (main.greedy_optimizer and some others)
-
Monty authored
Other things: - Renamed "rowid_filter_key" to "rowid_filter_index" to keep things consistent
-
Vicențiu Ciorbaru authored
The old code had a bug when the normal sorting code where where eliminated as part of "Using index for group-by" optimization. The effect was that the result contained more rows than expected
-
Monty authored
InnoDB FTS scan was used by a subquery. A subquery execution may start a table read and continue until it finds the first matching record combination. This can happen before the table read returns EOF. The next time the subquery is executed, it will start another table read. InnoDB FTS table read fails to re-initialize its data structures in this scenario and will try to continue the scan started at the first execution. Fixed by ha_innobase::ft_init() to stop the FTS scan if there is one. Author: Sergei Petrunia <sergey@mariadb.com> Reviewer: Monty
-
Monty authored
- table_after_join_selectivity() should use records_init (new bug) - get_examined_rows() changed to double to get similar results as in MariaDB 10.11 - Fixed bug where table_after_join_selectivity() did not correct selectivity in the case where a RANGE is used instead of a REF. This can happen if the range can use more key_parts than the REF. WHERE key_part1=10 and key_part2 < 10 Other things: - Use JT_RANGE instead of JT_ALL for RANGE access in all parts of the code. Before we used JT_ALL for RANGE. - Force RANGE be used in best_access_path() if the range used more key parts than ref. In the original code, this was done much later in make_join_select)(). However we need to know in table_after_join_selectivity() if we have used RANGE or not. - Added more information about filtering to optimizer_trace.
-
Monty authored
The reason is that 2 is usually way to low and as information_schema tables may have implicit locks when accessing rows, it is better that the optimizer doesn't think that these tables are 'very small and fast'. This change will affect a very small set of test cases.
-
Monty authored
-
Monty authored
The argument was not used.
-
Monty authored
Before the cost of an aggregate distinct (COUNT(DISTINCT ...)) was set to 0 if the values where part of an index and the cost of grouping was higher than the best cost so far. This was shown in explain with "Using index for group-by (scanning)". This patch fixes it by calculating the cost of aggregate distinct and using scanning only if the cost was better than group-by-optimization. Thing taken into account: - When using aggregate distinct on index, the filtering is done before the row is checked against the WHERE and we have thus less WHERE cost. - When comparing a cost from aggregate distinct, we add to the compared to plan the cost of doing the filtering later in the SQL level.
-
Monty authored
Allows FirstMatch to handle the case where the fanout of firstmatch tables is already less than 1. Also Fixes LooseScan strategy to set position->{records_init, records_out} (They were set to 0 which also caused assertion failures) Author: Sergei Petrunia <sergey@mariadb.com> Reviewer: Monty
-
Monty authored
-
Monty authored
This happens when the subquery marks some index fields as constant but the fields are still present in GROUP BY Fixed by checking if the 'constant field' is still part of GROUP BY before skipping it. Other things: - Added Item_field::contains() to make it easier to check if a field is equal to a Item_field or part of Item_equal.
-
Monty authored
This solves the current problem in the optimizer - SELECT FROM big_table - SELECT from small_table where small_table.eq_ref_key=big_table.id The old code assumed that each eq_ref access will cause an IO. As the cost of IO is high, this dominated the cost for the later table which caused the optimizer to prefer table scans + join cache over index reads. This patch fixes this issue by limit the number of expected IO calls, for rows and index separately, to the size of the table or index or the number of accesses that we except in a range for the index. The major changes are: - Adding a new structure ALL_READ_COST that is mainly used in best_access_path() to hold the costs parts of the cost we are calculating. This allows us to limit the number of IO when multiplying the cost with the previous row combinations. - All storage engine cost functions are changed to return IO_AND_CPU_COST. The virtual cost functions should now return in IO_AND_CPU_COST.io the number of disk blocks that will be accessed instead of the cost of the access. - We are not limiting the io_blocks for table or index scans as we assume that engines may not store these in the 'hot' part of the cache. Table and index scan also uses much less IO blocks than key accesses, so the original issue is not as critical with scans. Other things: OPT_RANGE now holds a 'Cost_estimate cost' instead a lot of different costs. All the old costs, like index_only_read, can be extracted from 'cost'. - Added to the start of some functions 'handler *file= table->file' to shorten the code that is using the handler. - handler->cost() is used to change a ALL_READ_COST or IO_AND_CPU_COST to 'cost in milliseconds' - New functions: handler::index_blocks() and handler::row_blocks() which are used to limit the IO. - Added index_cost and row_cost to Cost_estimate and removed all not needed members. - Removed cost coefficients from Cost_estimate as these don't make sense when costs (except IO_BLOCKS) are in milliseconds. - Removed handler::avg_io_cost() and replaced it with DISK_READ_COST. - Renamed best_range_rowid_filter_for_partial_join() to best_range_rowid_filter() as using the old name made rows too long. - Changed all SJ_MATERIALIZATION_INFO 'Cost_estimate' variables to 'double' as Cost_estimate power was not used for these and thus just caused storage and performance overhead. - Changed cost_for_index_read() to use 'worst_seeks' to only limit IO, not number of table accesses. With this patch worst_seeks is probably not needed anymore, but I kept it around just in case. - Applying cost for filter got to be much shorter and easier thanks to the API changes. - Adjusted cost for fulltext keys in collaboration with Sergei Golubchik. - Most test changes caused by this patch is that table scans are changed to use indexes. - Added ha_seq::keyread_time() and ha_seq::key_scan_time() to get make checking number of potential IO blocks easier during debugging.
-
Monty authored
If the final range restrictions (SEL_ARG tree) over GROUP BY columns are single-point, we can compute the number of GROUP BY groups. Example: in the query: SELECT ... FROM tbl WHERE keypart1 IN (1,2,3) and keypart2 IN ('foo','bar') Other things: - Fixed cost calculation to more correctly count the number of blocks that may be read. The old code could use the total blocks in the file even if a range was available.
-