/
usr
/
include
/
mysql
/
server
/
private
/
/usr/include/mysql/server/private
mkdir
upload
Name
Size
Mode
Actions
atomic/
-
0755
rm
data/
-
0755
rm
providers/
-
0755
rm
aligned.h
1136
0644
edit
dl
rm
aria_backup.h
1787
0644
edit
dl
rm
assume_aligned.h
2350
0644
edit
dl
rm
authors.h
10141
0644
edit
dl
rm
backup.h
1703
0644
edit
dl
rm
bounded_queue.h
6093
0644
edit
dl
rm
client_settings.h
1935
0644
edit
dl
rm
compat56.h
2280
0644
edit
dl
rm
config.h
14543
0644
edit
dl
rm
contributors.h
4878
0644
edit
dl
rm
create_options.h
4193
0644
edit
dl
rm
create_tmp_table.h
2808
0644
edit
dl
rm
cset_narrowing.h
3968
0644
edit
dl
rm
custom_conf.h
1082
0644
edit
dl
rm
datadict.h
1700
0644
edit
dl
rm
ddl_log.h
12807
0644
edit
dl
rm
debug.h
1234
0644
edit
dl
rm
debug_sync.h
2046
0644
edit
dl
rm
derived_handler.h
2379
0644
edit
dl
rm
derror.h
980
0644
edit
dl
rm
des_key_file.h
1236
0644
edit
dl
rm
discover.h
1570
0644
edit
dl
rm
dur_prop.h
1082
0644
edit
dl
rm
embedded_priv.h
1733
0644
edit
dl
rm
events.h
4704
0644
edit
dl
rm
event_data_objects.h
4187
0644
edit
dl
rm
event_db_repository.h
3648
0644
edit
dl
rm
event_parse_data.h
2899
0644
edit
dl
rm
event_queue.h
3438
0644
edit
dl
rm
event_scheduler.h
3290
0644
edit
dl
rm
field.h
222336
0644
edit
dl
rm
field_comp.h
1174
0644
edit
dl
rm
filesort.h
7283
0644
edit
dl
rm
filesort_utils.h
8195
0644
edit
dl
rm
ft_global.h
3113
0644
edit
dl
rm
gcalc_slicescan.h
17272
0644
edit
dl
rm
gcalc_tools.h
11900
0644
edit
dl
rm
grant.h
2758
0644
edit
dl
rm
group_by_handler.h
3534
0644
edit
dl
rm
gstream.h
2437
0644
edit
dl
rm
handler.h
199730
0644
edit
dl
rm
handle_connections_win.h
884
0644
edit
dl
rm
hash.h
4452
0644
edit
dl
rm
hash_filo.h
5688
0644
edit
dl
rm
ha_handler_stats.h
2335
0644
edit
dl
rm
ha_partition.h
64696
0644
edit
dl
rm
ha_sequence.h
6245
0644
edit
dl
rm
heap.h
9480
0644
edit
dl
rm
hostname.h
5419
0644
edit
dl
rm
ilist.h
7237
0644
edit
dl
rm
init.h
852
0644
edit
dl
rm
innodb_priv.h
1319
0644
edit
dl
rm
item.h
283188
0644
edit
dl
rm
item_cmpfunc.h
135071
0644
edit
dl
rm
item_create.h
11508
0644
edit
dl
rm
item_func.h
138638
0644
edit
dl
rm
item_geofunc.h
39612
0644
edit
dl
rm
item_jsonfunc.h
25264
0644
edit
dl
rm
item_row.h
5229
0644
edit
dl
rm
item_strfunc.h
74995
0644
edit
dl
rm
item_subselect.h
59028
0644
edit
dl
rm
item_sum.h
72695
0644
edit
dl
rm
item_timefunc.h
65896
0644
edit
dl
rm
item_vers.h
4413
0644
edit
dl
rm
item_windowfunc.h
34556
0644
edit
dl
rm
item_xmlfunc.h
4650
0644
edit
dl
rm
json_table.h
9667
0644
edit
dl
rm
key.h
2132
0644
edit
dl
rm
keycaches.h
1995
0644
edit
dl
rm
lex.h
29840
0644
edit
dl
rm
lex_charset.h
24313
0644
edit
dl
rm
lex_hash.h
143108
0644
edit
dl
rm
lex_ident.h
2122
0644
edit
dl
rm
lex_string.h
4077
0644
edit
dl
rm
lex_symbol.h
1323
0644
edit
dl
rm
lex_token.h
42641
0644
edit
dl
rm
lf.h
6462
0644
edit
dl
rm
lock.h
2220
0644
edit
dl
rm
log.h
46370
0644
edit
dl
rm
log_event.h
189106
0644
edit
dl
rm
log_event_data_type.h
1890
0644
edit
dl
rm
log_event_old.h
19830
0644
edit
dl
rm
log_slow.h
2442
0644
edit
dl
rm
maria.h
5872
0644
edit
dl
rm
mariadb.h
1277
0644
edit
dl
rm
mdl.h
38503
0644
edit
dl
rm
mem_root_array.h
7106
0644
edit
dl
rm
message.h
1195
0644
edit
dl
rm
multi_range_read.h
23179
0644
edit
dl
rm
myisam.h
17506
0644
edit
dl
rm
myisamchk.h
4734
0644
edit
dl
rm
myisammrg.h
4897
0644
edit
dl
rm
myisampack.h
14929
0644
edit
dl
rm
mysqld.h
41063
0644
edit
dl
rm
mysqld_default_groups.h
204
0644
edit
dl
rm
mysqld_suffix.h
1201
0644
edit
dl
rm
mysys_err.h
3022
0644
edit
dl
rm
my_alarm.h
2429
0644
edit
dl
rm
my_apc.h
4747
0644
edit
dl
rm
my_atomic.h
7281
0644
edit
dl
rm
my_atomic_wrapper.h
3051
0644
edit
dl
rm
my_base.h
27656
0644
edit
dl
rm
my_bit.h
6196
0644
edit
dl
rm
my_bitmap.h
5502
0644
edit
dl
rm
my_check_opt.h
2618
0644
edit
dl
rm
my_compare.h
11194
0644
edit
dl
rm
my_counter.h
1721
0644
edit
dl
rm
my_cpu.h
4855
0644
edit
dl
rm
my_crypt.h
904
0644
edit
dl
rm
my_decimal.h
14489
0644
edit
dl
rm
my_default.h
1880
0644
edit
dl
rm
my_handler_errors.h
4882
0644
edit
dl
rm
my_json_writer.h
18573
0644
edit
dl
rm
my_libwrap.h
1183
0644
edit
dl
rm
my_md5.h
1486
0644
edit
dl
rm
my_minidump.h
848
0644
edit
dl
rm
my_nosys.h
1438
0644
edit
dl
rm
my_rdtsc.h
10119
0644
edit
dl
rm
my_rnd.h
1014
0644
edit
dl
rm
my_service_manager.h
2087
0644
edit
dl
rm
my_stacktrace.h
3215
0644
edit
dl
rm
my_stack_alloc.h
6493
0644
edit
dl
rm
my_time.h
10414
0644
edit
dl
rm
my_tree.h
3991
0644
edit
dl
rm
my_uctype.h
69528
0644
edit
dl
rm
my_user.h
1126
0644
edit
dl
rm
my_virtual_mem.h
1127
0644
edit
dl
rm
opt_histogram_json.h
4638
0644
edit
dl
rm
opt_range.h
65903
0644
edit
dl
rm
opt_subselect.h
14545
0644
edit
dl
rm
opt_trace.h
8494
0644
edit
dl
rm
opt_trace_context.h
3291
0644
edit
dl
rm
parse_file.h
4387
0644
edit
dl
rm
partition_element.h
5428
0644
edit
dl
rm
partition_info.h
19864
0644
edit
dl
rm
password.h
1170
0644
edit
dl
rm
pfs_file_provider.h
3153
0644
edit
dl
rm
pfs_idle_provider.h
1385
0644
edit
dl
rm
pfs_memory_provider.h
1626
0644
edit
dl
rm
pfs_metadata_provider.h
1898
0644
edit
dl
rm
pfs_socket_provider.h
2258
0644
edit
dl
rm
pfs_stage_provider.h
1556
0644
edit
dl
rm
pfs_statement_provider.h
4347
0644
edit
dl
rm
pfs_table_provider.h
2625
0644
edit
dl
rm
pfs_thread_provider.h
5560
0644
edit
dl
rm
pfs_transaction_provider.h
2846
0644
edit
dl
rm
privilege.h
28889
0644
edit
dl
rm
probes_mysql.h
973
0644
edit
dl
rm
probes_mysql_nodtrace.h
6087
0644
edit
dl
rm
procedure.h
6819
0644
edit
dl
rm
protocol.h
12537
0644
edit
dl
rm
proxy_protocol.h
548
0644
edit
dl
rm
queues.h
3477
0644
edit
dl
rm
records.h
3147
0644
edit
dl
rm
replication.h
16130
0644
edit
dl
rm
repl_failsafe.h
1585
0644
edit
dl
rm
rijndael.h
1711
0644
edit
dl
rm
rowid_filter.h
15474
0644
edit
dl
rm
rpl_constants.h
3357
0644
edit
dl
rm
rpl_filter.h
4774
0644
edit
dl
rm
rpl_gtid.h
29939
0644
edit
dl
rm
rpl_injector.h
9621
0644
edit
dl
rm
rpl_mi.h
16638
0644
edit
dl
rm
rpl_parallel.h
18228
0644
edit
dl
rm
rpl_record.h
1585
0644
edit
dl
rm
rpl_record_old.h
1407
0644
edit
dl
rm
rpl_reporting.h
3713
0644
edit
dl
rm
rpl_rli.h
36070
0644
edit
dl
rm
rpl_tblmap.h
3177
0644
edit
dl
rm
rpl_utility.h
9630
0644
edit
dl
rm
scheduler.h
3199
0644
edit
dl
rm
scope.h
4393
0644
edit
dl
rm
select_handler.h
2228
0644
edit
dl
rm
semisync.h
2287
0644
edit
dl
rm
semisync_master.h
25766
0644
edit
dl
rm
semisync_master_ack_receiver.h
8709
0644
edit
dl
rm
semisync_slave.h
3736
0644
edit
dl
rm
service_versions.h
2285
0644
edit
dl
rm
session_tracker.h
14275
0644
edit
dl
rm
set_var.h
16551
0644
edit
dl
rm
slave.h
12275
0644
edit
dl
rm
socketpair.h
842
0644
edit
dl
rm
source_revision.h
67
0644
edit
dl
rm
sp.h
22588
0644
edit
dl
rm
span.h
3931
0644
edit
dl
rm
spatial.h
22698
0644
edit
dl
rm
sp_cache.h
2037
0644
edit
dl
rm
sp_head.h
64917
0644
edit
dl
rm
sp_pcontext.h
24893
0644
edit
dl
rm
sp_rcontext.h
14441
0644
edit
dl
rm
sql_acl.h
14167
0644
edit
dl
rm
sql_admin.h
2915
0644
edit
dl
rm
sql_alloc.h
1732
0644
edit
dl
rm
sql_alter.h
15395
0644
edit
dl
rm
sql_analyse.h
11125
0644
edit
dl
rm
sql_analyze_stmt.h
12683
0644
edit
dl
rm
sql_array.h
6858
0644
edit
dl
rm
sql_audit.h
14162
0644
edit
dl
rm
sql_base.h
26041
0644
edit
dl
rm
sql_basic_types.h
9523
0644
edit
dl
rm
sql_binlog.h
895
0644
edit
dl
rm
sql_bitmap.h
7842
0644
edit
dl
rm
sql_bootstrap.h
1812
0644
edit
dl
rm
sql_cache.h
21676
0644
edit
dl
rm
sql_callback.h
1542
0644
edit
dl
rm
sql_class.h
271120
0644
edit
dl
rm
sql_cmd.h
5962
0644
edit
dl
rm
sql_command.h
4800
0644
edit
dl
rm
sql_connect.h
4087
0644
edit
dl
rm
sql_const.h
11415
0644
edit
dl
rm
sql_crypt.h
1437
0644
edit
dl
rm
sql_cte.h
16494
0644
edit
dl
rm
sql_cursor.h
4239
0644
edit
dl
rm
sql_db.h
2438
0644
edit
dl
rm
sql_debug.h
5646
0644
edit
dl
rm
sql_delete.h
1343
0644
edit
dl
rm
sql_derived.h
1289
0644
edit
dl
rm
sql_digest.h
3819
0644
edit
dl
rm
sql_digest_stream.h
1567
0644
edit
dl
rm
sql_do.h
954
0644
edit
dl
rm
sql_error.h
39843
0644
edit
dl
rm
sql_explain.h
30319
0644
edit
dl
rm
sql_expression_cache.h
4359
0644
edit
dl
rm
sql_get_diagnostics.h
7883
0644
edit
dl
rm
sql_handler.h
2910
0644
edit
dl
rm
sql_help.h
995
0644
edit
dl
rm
sql_hset.h
3401
0644
edit
dl
rm
sql_insert.h
5173
0644
edit
dl
rm
sql_i_s.h
8487
0644
edit
dl
rm
sql_join_cache.h
48659
0644
edit
dl
rm
sql_lex.h
174693
0644
edit
dl
rm
sql_lifo_buffer.h
9676
0644
edit
dl
rm
sql_limit.h
3187
0644
edit
dl
rm
sql_list.h
22391
0644
edit
dl
rm
sql_load.h
1276
0644
edit
dl
rm
sql_locale.h
2701
0644
edit
dl
rm
sql_manager.h
960
0644
edit
dl
rm
sql_mode.h
6735
0644
edit
dl
rm
sql_parse.h
8970
0644
edit
dl
rm
sql_partition.h
12674
0644
edit
dl
rm
sql_partition_admin.h
5940
0644
edit
dl
rm
sql_plist.h
7711
0644
edit
dl
rm
sql_plugin.h
7577
0644
edit
dl
rm
sql_plugin_compat.h
2237
0644
edit
dl
rm
sql_prepare.h
11409
0644
edit
dl
rm
sql_priv.h
18474
0644
edit
dl
rm
sql_profile.h
7816
0644
edit
dl
rm
sql_reload.h
1036
0644
edit
dl
rm
sql_rename.h
982
0644
edit
dl
rm
sql_repl.h
3045
0644
edit
dl
rm
sql_schema.h
3303
0644
edit
dl
rm
sql_select.h
89743
0644
edit
dl
rm
sql_sequence.h
5177
0644
edit
dl
rm
sql_servers.h
1777
0644
edit
dl
rm
sql_show.h
9830
0644
edit
dl
rm
sql_signal.h
3362
0644
edit
dl
rm
sql_sort.h
21964
0644
edit
dl
rm
sql_statistics.h
16494
0644
edit
dl
rm
sql_string.h
39009
0644
edit
dl
rm
sql_table.h
9752
0644
edit
dl
rm
sql_test.h
1589
0644
edit
dl
rm
sql_time.h
8374
0644
edit
dl
rm
sql_trigger.h
12332
0644
edit
dl
rm
sql_truncate.h
2079
0644
edit
dl
rm
sql_tvc.h
2418
0644
edit
dl
rm
sql_type.h
296072
0644
edit
dl
rm
sql_type_fixedbin.h
65578
0644
edit
dl
rm
sql_type_fixedbin_storage.h
5467
0644
edit
dl
rm
sql_type_geom.h
19039
0644
edit
dl
rm
sql_type_int.h
10001
0644
edit
dl
rm
sql_type_json.h
6155
0644
edit
dl
rm
sql_type_real.h
1257
0644
edit
dl
rm
sql_type_string.h
1629
0644
edit
dl
rm
sql_udf.h
4850
0644
edit
dl
rm
sql_union.h
1068
0644
edit
dl
rm
sql_update.h
1923
0644
edit
dl
rm
sql_view.h
2470
0644
edit
dl
rm
sql_window.h
6814
0644
edit
dl
rm
ssl_compat.h
3380
0644
edit
dl
rm
strfunc.h
2275
0644
edit
dl
rm
structs.h
29530
0644
edit
dl
rm
sys_vars_shared.h
2729
0644
edit
dl
rm
table.h
118414
0644
edit
dl
rm
table_cache.h
4232
0644
edit
dl
rm
threadpool.h
4810
0644
edit
dl
rm
threadpool_generic.h
3969
0644
edit
dl
rm
threadpool_winsockets.h
2290
0644
edit
dl
rm
thread_cache.h
5905
0644
edit
dl
rm
thr_alarm.h
2932
0644
edit
dl
rm
thr_lock.h
7350
0644
edit
dl
rm
thr_malloc.h
1202
0644
edit
dl
rm
thr_timer.h
1563
0644
edit
dl
rm
transaction.h
1466
0644
edit
dl
rm
tzfile.h
5014
0644
edit
dl
rm
tztime.h
3397
0644
edit
dl
rm
t_ctype.h
5639
0644
edit
dl
rm
uniques.h
4217
0644
edit
dl
rm
unireg.h
7722
0644
edit
dl
rm
vers_string.h
2543
0644
edit
dl
rm
violite.h
10086
0644
edit
dl
rm
waiting_threads.h
4532
0644
edit
dl
rm
welcome_copyright_notice.h
1218
0644
edit
dl
rm
winservice.h
6019
0644
edit
dl
rm
win_tzname_data.h
6506
0644
edit
dl
rm
wqueue.h
1565
0644
edit
dl
rm
wsrep.h
3308
0644
edit
dl
rm
wsrep_allowlist_service.h
1035
0644
edit
dl
rm
wsrep_applier.h
2703
0644
edit
dl
rm
wsrep_binlog.h
3551
0644
edit
dl
rm
wsrep_client_service.h
2560
0644
edit
dl
rm
wsrep_client_state.h
1566
0644
edit
dl
rm
wsrep_condition_variable.h
1484
0644
edit
dl
rm
wsrep_high_priority_service.h
4912
0644
edit
dl
rm
wsrep_mutex.h
1239
0644
edit
dl
rm
wsrep_mysqld.h
21524
0644
edit
dl
rm
wsrep_mysqld_c.h
1227
0644
edit
dl
rm
wsrep_on.h
1718
0644
edit
dl
rm
wsrep_priv.h
1634
0644
edit
dl
rm
wsrep_schema.h
5608
0644
edit
dl
rm
wsrep_server_service.h
3631
0644
edit
dl
rm
wsrep_server_state.h
2529
0644
edit
dl
rm
wsrep_sst.h
3951
0644
edit
dl
rm
wsrep_status.h
1816
0644
edit
dl
rm
wsrep_storage_service.h
1809
0644
edit
dl
rm
wsrep_thd.h
11487
0644
edit
dl
rm
wsrep_trans_observer.h
18174
0644
edit
dl
rm
wsrep_types.h
1110
0644
edit
dl
rm
wsrep_utils.h
9807
0644
edit
dl
rm
wsrep_var.h
4491
0644
edit
dl
rm
wsrep_xid.h
1549
0644
edit
dl
rm
xa.h
1845
0644
edit
dl
rm
Edit:
/usr/include/mysql/server/private/rowid_filter.h
(15474B)
/* Copyright (c) 2018, 2019 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 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-1301 USA */ #ifndef ROWID_FILTER_INCLUDED #define ROWID_FILTER_INCLUDED #include "mariadb.h" #include "sql_array.h" /* What rowid / primary filters are -------------------------------- Consider a join query Q of the form SELECT * FROM T1, ... , Tk WHERE P. For any of the table reference Ti(Q) from the from clause of Q different rowid / primary key filters (pk-filters for short) can be built. A pk-filter F built for Ti(Q) is a set of rowids / primary keys of Ti F= {pk1,...,pkN} such that for any row r=r1||...||rk from the result set of Q ri's rowid / primary key pk(ri) is contained in F. When pk-filters are useful -------------------------- If building a pk-filter F for Ti(Q )is not too costly and its cardinality #F is much less than the cardinality of T - #T then using the pk-filter when executing Q might be quite beneficial. Let r be a random row from Ti. Let s(F) be the probability that pk(r) belongs to F. Let BC(F) be the cost of building F. Suppose that the optimizer has chosen for Q a plan with this join order T1 => ... Tk and that the table Ti is accessed by a ref access using index I. Let K = {k1,...,kM} be the set of all rowid/primary keys values used to access rows of Ti when looking for matches in this table.to join Ti by index I. Let's assume that two set sets K and F are uncorrelated. With this assumption if before accessing data from Ti by the rowid / primary key k we first check whether k is in F then we can expect saving on M*(1-s(S)) accesses of data rows from Ti. If we can guarantee that test whether k is in F is relatively cheap then we can gain a lot assuming that BC(F) is much less then the cost of fetching M*(1-s(S)) records from Ti and following evaluation of conditions pushed into Ti. Making pk-filter test cheap --------------------------- If the search structure to test whether an element is in F can be fully placed in RAM then this test is expected to be much cheaper than a random access of a record from Ti. We'll consider two search structures for pk-filters: ordered array and bloom filter. Ordered array is easy to implement, but it's space consuming. If a filter contains primary keys then at least space for each primary key from the filter must be allocated in the search structure. On a the opposite a bloom filter requires a fixed number of bits and this number does not depend on the cardinality of the pk-filter (10 bits per element will serve pk-filter of any size). */ /* How and when the optimizer builds and uses range rowid filters -------------------------------------------------------------- 1. In make_join_statistics() for each join table s after the call of get_quick_record_count() the TABLE::method init_cost_info_for_usable_range_rowid_filters() is called The method build an array of Range_rowid_filter_cost_info elements containing the cost info on possible range filters for s->table. The array is optimized for further usage. 2. For each partial join order when the optimizer considers joining table s to this partial join In the function best_access_path() a. When evaluating a ref access r by index idx to join s the optimizer estimates the effect of usage of each possible range filter f and chooses one with the best gain. The gain is taken into account when the cost of thr ref access r is calculated. If it turns out that this is the best ref access to join s then the info about the chosen filter together with the info on r is remembered in the corresponding element of the array of POSITION structures. [We evaluate every pair (ref access, range_filter) rather then every pair (best ref access, range filter) because if the index ref_idx used for ref access r correlates with the index rf_idx used by the filter f then the pair (r,f) is not evaluated at all as we don't know how to estimate the effect of correlation between ref_idx and rf_idx.] b. When evaluating the best range access to join table s the optimizer estimates the effect of usage of each possible range filter f and chooses one with the best gain. [Here we should have evaluated every pair (range access, range filter) as well, but it's not done yet.] 3. When the cheapest execution plan has been chosen and after the call of JOIN::get_best_combination() The method JOIN::make_range_rowid_filters() is called For each range rowid filter used in the chosen execution plan the method creates a quick select object to be able to perform index range scan to fill the filter at the execution stage. The method also creates Range_rowid_filter objects that are used at the execution stage. 4. Just before the execution stage The method JOIN::init_range_rowid_filters() is called. For each join table s that is to be accessed with usage of a range filter the method allocates containers for the range filter and it lets the engine know that the filter will be used when accessing s. 5. At the execution stage In the function sub_select() just before the first access of a join table s employing a range filter The method JOIN_TAB::build_range_rowid_filter_if_needed() is called The method fills the filter using the quick select created by JOIN::make_range_rowid_filters(). 6. The accessed key tuples are checked against the filter within the engine using the info pushed into it. */ struct TABLE; class SQL_SELECT; class Rowid_filter_container; class Range_rowid_filter_cost_info; /* Cost to write rowid into array */ #define ARRAY_WRITE_COST 0.005 /* Factor used to calculate cost of sorting rowids in array */ #define ARRAY_SORT_C 0.01 /* Cost to evaluate condition */ #define COST_COND_EVAL 0.2 typedef enum { SORTED_ARRAY_CONTAINER, BLOOM_FILTER_CONTAINER // Not used yet } Rowid_filter_container_type; /** @class Rowid_filter_container The interface for different types of containers to store info on the set of rowids / primary keys that defines a pk-filter. There will be two implementations of this abstract class. - sorted array - bloom filter */ class Rowid_filter_container : public Sql_alloc { public: virtual Rowid_filter_container_type get_type() = 0; /* Allocate memory for the container */ virtual bool alloc() = 0; /* @brief Add info on a rowid / primary to the container @param ctxt The context info (opaque) @param elem The rowid / primary key to be added to the container @retval true if elem is successfully added */ virtual bool add(void *ctxt, char *elem) = 0; /* @brief Check whether a rowid / primary key is in container @param ctxt The context info (opaque) @param elem The rowid / primary key to be checked against the container @retval False if elem is definitely not in the container */ virtual bool check(void *ctxt, char *elem) = 0; /* True if the container does not contain any element */ virtual bool is_empty() = 0; virtual ~Rowid_filter_container() = default; }; /** @class Rowid_filter The interface for different types of pk-filters Currently we support only range pk filters. */ class Rowid_filter : public Sql_alloc { protected: /* The container to store info the set of elements in the filter */ Rowid_filter_container *container; Rowid_filter_tracker *tracker; public: enum build_return_code { SUCCESS, NON_FATAL_ERROR, FATAL_ERROR, }; Rowid_filter(Rowid_filter_container *container_arg) : container(container_arg) {} /* Build the filter : fill it with info on the set of elements placed there */ virtual build_return_code build() = 0; /* Check whether an element is in the filter. Returns false is the elements is definitely not in the filter. */ virtual bool check(char *elem) = 0; virtual ~Rowid_filter() = default; bool is_empty() { return container->is_empty(); } Rowid_filter_container *get_container() { return container; } void set_tracker(Rowid_filter_tracker *track_arg) { tracker= track_arg; } Rowid_filter_tracker *get_tracker() { return tracker; } }; /** @class Rowid_filter_container The implementation of the Rowid_interface used for pk-filters that are filled when performing range index scans. */ class Range_rowid_filter: public Rowid_filter { /* The table for which the rowid filter is built */ TABLE *table; /* The select to perform the range scan to fill the filter */ SQL_SELECT *select; /* The cost info on the filter (used for EXPLAIN/ANALYZE) */ Range_rowid_filter_cost_info *cost_info; public: Range_rowid_filter(TABLE *tab, Range_rowid_filter_cost_info *cost_arg, Rowid_filter_container *container_arg, SQL_SELECT *sel) : Rowid_filter(container_arg), table(tab), select(sel), cost_info(cost_arg) {} ~Range_rowid_filter(); build_return_code build() override; bool check(char *elem) override { if (container->is_empty()) return false; bool was_checked= container->check(table, elem); tracker->increment_checked_elements_count(was_checked); return was_checked; } SQL_SELECT *get_select() { return select; } }; /** @class Refpos_container_sorted_array The wrapper class over Dynamic_array<char> to facilitate operations over array of elements of the type char[N] where N is the same for all elements */ class Refpos_container_sorted_array : public Sql_alloc { /* Maximum number of elements in the array (Now is used only at the initialization of the dynamic array) */ uint max_elements; /* Number of bytes allocated for an element */ uint elem_size; /* The dynamic array over which the wrapper is built */ Dynamic_array<char> *array; public: Refpos_container_sorted_array(uint max_elems, uint elem_sz) : max_elements(max_elems), elem_size(elem_sz), array(0) {} ~Refpos_container_sorted_array() { delete array; array= 0; } bool alloc() { array= new Dynamic_array<char> (PSI_INSTRUMENT_MEM, elem_size * max_elements, elem_size * max_elements/sizeof(char) + 1); return array == NULL; } bool add(char *elem) { for (uint i= 0; i < elem_size; i++) { if (array->append(elem[i])) return true; } return false; } char *get_pos(uint n) { return array->get_pos(n * elem_size); } uint elements() { return (uint) (array->elements() / elem_size); } void sort(qsort_cmp2 cmp, void *cmp_arg) { my_qsort2(array->front(), array->elements() / elem_size, elem_size, cmp, cmp_arg); } bool is_empty() { return elements() == 0; } }; /** @class Rowid_filter_sorted_array The implementation of the Rowid_filter_container interface as a sorted array container of rowids / primary keys */ class Rowid_filter_sorted_array: public Rowid_filter_container { /* The dynamic array to store rowids / primary keys */ Refpos_container_sorted_array refpos_container; /* Initially false, becomes true after the first call of (check() */ bool is_checked; public: Rowid_filter_sorted_array(uint elems, uint elem_size) : refpos_container(elems, elem_size), is_checked(false) {} Rowid_filter_container_type get_type() override { return SORTED_ARRAY_CONTAINER; } bool alloc() override { return refpos_container.alloc(); } bool add(void *ctxt, char *elem) override { return refpos_container.add(elem); } bool check(void *ctxt, char *elem) override; bool is_empty() override { return refpos_container.is_empty(); } }; /** @class Range_rowid_filter_cost_info An objects of this class is created for each potentially usable range filter. It contains the info that allows to figure out whether usage of the range filter promises some gain. */ class Range_rowid_filter_cost_info : public Sql_alloc { /* The table for which the range filter is to be built (if needed) */ TABLE *table; /* Estimated number of elements in the filter */ ulonglong est_elements; /* The cost of building the range filter */ double b; /* a*N-b yields the gain of the filter for N key tuples of the index key_no */ double a; /* The value of N where the gain is 0 */ double cross_x; /* Used for pruning of the potential range filters */ key_map abs_independent; /* These two parameters are used to choose the best range filter in the function TABLE::best_range_rowid_filter_for_partial_join */ double a_adj; double cross_x_adj; public: /* The type of the container of the range filter */ Rowid_filter_container_type container_type; /* The index whose range scan would be used to build the range filter */ uint key_no; /* The selectivity of the range filter */ double selectivity; Range_rowid_filter_cost_info() : table(0), key_no(0) {} void init(Rowid_filter_container_type cont_type, TABLE *tab, uint key_no); double build_cost(Rowid_filter_container_type container_type); inline double lookup_cost(Rowid_filter_container_type cont_type); inline double avg_access_and_eval_gain_per_row(Rowid_filter_container_type cont_type); inline double avg_adjusted_gain_per_row(double access_cost_factor); inline void set_adjusted_gain_param(double access_cost_factor); /* Get the gain that usage of filter promises for r key tuples */ inline double get_gain(double r) { return r * a - b; } /* Get the adjusted gain that usage of filter promises for r key tuples */ inline double get_adjusted_gain(double r) { return r * a_adj - b; } /* The gain promised by usage of the filter for r key tuples due to less condition evaluations */ inline double get_cmp_gain(double r) { return r * (1 - selectivity) / TIME_FOR_COMPARE; } Rowid_filter_container *create_container(); double get_a() const { return a; } void trace_info(THD *thd); friend void TABLE::prune_range_rowid_filters(); friend void TABLE::init_cost_info_for_usable_range_rowid_filters(THD *thd); friend Range_rowid_filter_cost_info * TABLE::best_range_rowid_filter_for_partial_join(uint access_key_no, double records, double access_cost_factor); }; #endif /* ROWID_FILTER_INCLUDED */
Save
cmd:
run