2010-07-09 14:03:09 +02:00
|
|
|
//
|
2014-11-18 18:10:29 +01:00
|
|
|
// $Id: ha_sphinx.h 4818 2014-09-24 08:53:38Z tomat $
|
2010-07-09 14:03:09 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifdef USE_PRAGMA_INTERFACE
|
|
|
|
#pragma interface // gcc class implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-03-07 17:38:47 +02:00
|
|
|
#if MYSQL_VERSION_ID>=50515
|
2011-04-25 17:22:25 +02:00
|
|
|
#define TABLE_ARG TABLE_SHARE
|
2012-03-07 17:38:47 +02:00
|
|
|
#elif MYSQL_VERSION_ID>50100
|
|
|
|
#define TABLE_ARG st_table_share
|
2010-07-09 14:03:09 +02:00
|
|
|
#else
|
|
|
|
#define TABLE_ARG st_table
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if MYSQL_VERSION_ID>=50120
|
|
|
|
typedef uchar byte;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/// forward decls
|
|
|
|
class THD;
|
|
|
|
struct CSphReqQuery;
|
|
|
|
struct CSphSEShare;
|
|
|
|
struct CSphSEAttr;
|
|
|
|
struct CSphSEStats;
|
2014-11-18 18:10:29 +01:00
|
|
|
struct CSphSEThreadTable;
|
2010-07-09 14:03:09 +02:00
|
|
|
|
|
|
|
/// Sphinx SE handler class
|
2020-07-27 18:46:37 +03:00
|
|
|
class ha_sphinx final : public handler
|
2010-07-09 14:03:09 +02:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
THR_LOCK_DATA m_tLock; ///< MySQL lock
|
|
|
|
|
|
|
|
CSphSEShare * m_pShare; ///< shared lock info
|
|
|
|
|
|
|
|
uint m_iMatchesTotal;
|
|
|
|
uint m_iCurrentPos;
|
|
|
|
const byte * m_pCurrentKey;
|
|
|
|
uint m_iCurrentKeyLen;
|
|
|
|
|
|
|
|
char * m_pResponse; ///< searchd response storage
|
|
|
|
char * m_pResponseEnd; ///< searchd response storage end (points to wilderness!)
|
|
|
|
char * m_pCur; ///< current position into response
|
|
|
|
bool m_bUnpackError; ///< any errors while unpacking response
|
|
|
|
|
|
|
|
public:
|
|
|
|
#if MYSQL_VERSION_ID<50100
|
2012-03-07 17:38:47 +02:00
|
|
|
ha_sphinx ( TABLE_ARG * table_arg ); // NOLINT
|
2010-07-09 14:03:09 +02:00
|
|
|
#else
|
|
|
|
ha_sphinx ( handlerton * hton, TABLE_ARG * table_arg );
|
|
|
|
#endif
|
2012-03-07 17:38:47 +02:00
|
|
|
~ha_sphinx ();
|
2010-07-09 14:03:09 +02:00
|
|
|
|
2024-06-24 13:09:47 +03:00
|
|
|
const char * table_type () const override { return "SPHINX"; } ///< SE name for display purposes
|
2024-06-12 09:46:26 -04:00
|
|
|
const char * index_type ( uint ) override { return "HASH"; } ///< index type name for display purposes
|
2010-07-09 14:03:09 +02:00
|
|
|
|
|
|
|
#if MYSQL_VERSION_ID>50100
|
2024-06-12 09:46:26 -04:00
|
|
|
ulonglong table_flags () const override { return HA_CAN_INDEX_BLOBS |
|
2014-09-08 09:39:43 +02:00
|
|
|
HA_CAN_TABLE_CONDITION_PUSHDOWN; } ///< bitmap of implemented flags (see handler.h for more info)
|
2010-07-09 14:03:09 +02:00
|
|
|
#else
|
|
|
|
ulong table_flags () const { return HA_CAN_INDEX_BLOBS; } ///< bitmap of implemented flags (see handler.h for more info)
|
|
|
|
#endif
|
|
|
|
|
2024-06-12 09:46:26 -04:00
|
|
|
ulong index_flags ( uint, uint, bool ) const override { return 0; } ///< bitmap of flags that says how SE implements indexes
|
|
|
|
uint max_supported_record_length () const override { return HA_MAX_REC_LENGTH; }
|
|
|
|
uint max_supported_keys () const override { return 1; }
|
|
|
|
uint max_supported_key_parts () const override { return 1; }
|
|
|
|
uint max_supported_key_length () const override { return MAX_KEY_LENGTH; }
|
|
|
|
uint max_supported_key_part_length () const override { return MAX_KEY_LENGTH; }
|
2010-07-09 14:03:09 +02:00
|
|
|
|
2024-07-05 12:45:07 +02:00
|
|
|
IO_AND_CPU_COST scan_time () override
|
Changing all cost calculation to be given in milliseconds
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)
2022-08-11 13:05:23 +03:00
|
|
|
{
|
|
|
|
IO_AND_CPU_COST cost;
|
|
|
|
cost.io= 0;
|
2022-09-30 17:10:37 +03:00
|
|
|
cost.cpu= (double) (stats.records+stats.deleted) * DISK_READ_COST;
|
Changing all cost calculation to be given in milliseconds
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)
2022-08-11 13:05:23 +03:00
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
IO_AND_CPU_COST keyread_time(uint index, ulong ranges, ha_rows rows,
|
2024-07-05 12:45:07 +02:00
|
|
|
ulonglong blocks) override
|
Changing all cost calculation to be given in milliseconds
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)
2022-08-11 13:05:23 +03:00
|
|
|
{
|
|
|
|
IO_AND_CPU_COST cost;
|
|
|
|
cost.io= ranges;
|
|
|
|
cost.cpu= 0;
|
|
|
|
return cost;
|
|
|
|
}
|
2024-07-05 12:45:07 +02:00
|
|
|
IO_AND_CPU_COST rnd_pos_time(ha_rows rows) override
|
Changing all cost calculation to be given in milliseconds
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)
2022-08-11 13:05:23 +03:00
|
|
|
{
|
|
|
|
IO_AND_CPU_COST cost;
|
|
|
|
cost.io= 0;
|
|
|
|
cost.cpu= 0;
|
|
|
|
return cost;
|
|
|
|
}
|
2010-07-09 14:03:09 +02:00
|
|
|
|
|
|
|
public:
|
2024-06-12 09:46:26 -04:00
|
|
|
int open ( const char * name, int mode, uint test_if_locked ) override;
|
|
|
|
int close () override;
|
2010-07-09 14:03:09 +02:00
|
|
|
|
2024-06-12 09:46:26 -04:00
|
|
|
int write_row ( const byte * buf ) override;
|
|
|
|
int update_row ( const byte * old_data, const byte * new_data ) override;
|
|
|
|
int delete_row ( const byte * buf ) override;
|
|
|
|
int extra ( enum ha_extra_function op ) override;
|
2010-07-09 14:03:09 +02:00
|
|
|
|
2024-06-12 09:46:26 -04:00
|
|
|
int index_init ( uint keynr, bool sorted ) override; // 5.1.x
|
2010-07-09 14:03:09 +02:00
|
|
|
int index_init ( uint keynr ) { return index_init ( keynr, false ); } // 5.0.x
|
|
|
|
|
2024-06-12 09:46:26 -04:00
|
|
|
int index_end () override;
|
|
|
|
int index_read ( byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag ) override;
|
2010-07-09 14:03:09 +02:00
|
|
|
int index_read_idx ( byte * buf, uint idx, const byte * key, uint key_len, enum ha_rkey_function find_flag );
|
2024-06-12 09:46:26 -04:00
|
|
|
int index_next ( byte * buf ) override;
|
|
|
|
int index_next_same ( byte * buf, const byte * key, uint keylen ) override;
|
|
|
|
int index_prev ( byte * buf ) override;
|
|
|
|
int index_first ( byte * buf ) override;
|
|
|
|
int index_last ( byte * buf ) override;
|
2010-07-09 14:03:09 +02:00
|
|
|
|
|
|
|
int get_rec ( byte * buf, const byte * key, uint keylen );
|
|
|
|
|
2024-06-12 09:46:26 -04:00
|
|
|
int rnd_init ( bool scan ) override;
|
|
|
|
int rnd_end () override;
|
|
|
|
int rnd_next ( byte * buf ) override;
|
|
|
|
int rnd_pos ( byte * buf, byte * pos ) override;
|
|
|
|
void position ( const byte * record ) override;
|
2010-07-09 14:03:09 +02:00
|
|
|
|
|
|
|
#if MYSQL_VERSION_ID>=50030
|
2024-06-12 09:46:26 -04:00
|
|
|
int info ( uint ) override;
|
2010-07-09 14:03:09 +02:00
|
|
|
#else
|
|
|
|
void info ( uint );
|
|
|
|
#endif
|
|
|
|
|
2024-06-12 09:46:26 -04:00
|
|
|
int reset() override;
|
|
|
|
int external_lock ( THD * thd, int lock_type ) override;
|
|
|
|
int delete_all_rows () override;
|
|
|
|
ha_rows records_in_range ( uint inx, const key_range * min_key, const key_range * max_key, page_range *pages) override;
|
2010-07-09 14:03:09 +02:00
|
|
|
|
2024-06-12 09:46:26 -04:00
|
|
|
int delete_table ( const char * from ) override;
|
|
|
|
int rename_table ( const char * from, const char * to ) override;
|
|
|
|
int create ( const char * name, TABLE * form, HA_CREATE_INFO * create_info ) override;
|
2010-07-09 14:03:09 +02:00
|
|
|
|
2024-06-12 09:46:26 -04:00
|
|
|
THR_LOCK_DATA ** store_lock ( THD * thd, THR_LOCK_DATA ** to, enum thr_lock_type lock_type ) override;
|
2010-07-09 14:03:09 +02:00
|
|
|
|
|
|
|
public:
|
2014-02-01 10:56:56 +01:00
|
|
|
#if MYSQL_VERSION_ID<50610
|
2010-07-09 14:03:09 +02:00
|
|
|
virtual const COND * cond_push ( const COND *cond );
|
2014-02-01 10:56:56 +01:00
|
|
|
#else
|
2024-06-12 09:46:26 -04:00
|
|
|
const Item * cond_push ( const Item *cond ) override;
|
2014-02-01 10:56:56 +01:00
|
|
|
#endif
|
2024-06-12 09:46:26 -04:00
|
|
|
void cond_pop () override;
|
2010-07-09 14:03:09 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
uint32 m_iFields;
|
|
|
|
char ** m_dFields;
|
|
|
|
|
|
|
|
uint32 m_iAttrs;
|
|
|
|
CSphSEAttr * m_dAttrs;
|
|
|
|
int m_bId64;
|
|
|
|
|
|
|
|
int * m_dUnboundFields;
|
|
|
|
|
|
|
|
private:
|
2012-03-07 17:38:47 +02:00
|
|
|
int Connect ( const char * sQueryHost, ushort uPort );
|
|
|
|
int ConnectAPI ( const char * sQueryHost, int iQueryPort );
|
|
|
|
int HandleMysqlError ( struct st_mysql * pConn, int iErrCode );
|
2010-07-09 14:03:09 +02:00
|
|
|
|
|
|
|
uint32 UnpackDword ();
|
|
|
|
char * UnpackString ();
|
|
|
|
bool UnpackSchema ();
|
|
|
|
bool UnpackStats ( CSphSEStats * pStats );
|
2012-03-07 17:38:47 +02:00
|
|
|
bool CheckResponcePtr ( int iLen );
|
2010-07-09 14:03:09 +02:00
|
|
|
|
2014-11-18 18:10:29 +01:00
|
|
|
CSphSEThreadTable * GetTls ();
|
2010-07-09 14:03:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#if MYSQL_VERSION_ID < 50100
|
|
|
|
bool sphinx_show_status ( THD * thd );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
2014-11-18 18:10:29 +01:00
|
|
|
// $Id: ha_sphinx.h 4818 2014-09-24 08:53:38Z tomat $
|
2010-07-09 14:03:09 +02:00
|
|
|
//
|