Skip to content

Commit

Permalink
Added rowid_filter support to Aria
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
montywi authored and spetrunia committed Feb 3, 2023
1 parent 6418c24 commit 66dde8a
Show file tree
Hide file tree
Showing 36 changed files with 3,613 additions and 1,996 deletions.
1 change: 0 additions & 1 deletion include/my_compare.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,5 @@ typedef enum check_result {

typedef check_result_t (*index_cond_func_t)(void *param);
typedef check_result_t (*rowid_filter_func_t)(void *param);
typedef int (*rowid_filter_is_active_func_t)(void *param);

#endif /* _my_compare_h */
12 changes: 12 additions & 0 deletions include/my_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ typedef struct st_dynamic_array
myf malloc_flags;
} DYNAMIC_ARRAY;


typedef struct st_dynamic_array_append
{
DYNAMIC_ARRAY *array;
uchar *pos, *end;
} DYNAMIC_ARRAY_APPEND;


typedef struct st_my_tmpdir
{
DYNAMIC_ARRAY full_list;
Expand Down Expand Up @@ -856,6 +864,10 @@ extern void freeze_size(DYNAMIC_ARRAY *array);
#define push_dynamic(A,B) insert_dynamic((A),(B))
#define reset_dynamic(array) ((array)->elements= 0)
#define sort_dynamic(A,cmp) my_qsort((A)->buffer, (A)->elements, (A)->size_of_element, (cmp))
extern void init_append_dynamic(DYNAMIC_ARRAY_APPEND *append,
DYNAMIC_ARRAY *array);
extern my_bool append_dynamic(DYNAMIC_ARRAY_APPEND *append,
const void * element);

extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
size_t init_alloc,size_t alloc_increment);
Expand Down
22 changes: 11 additions & 11 deletions mysql-test/main/opt_trace.result
Original file line number Diff line number Diff line change
Expand Up @@ -12239,32 +12239,32 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
"rowid_filter_index": "b",
"index_only_cost": 0.001515222,
"filter_startup_cost": 3.004222e-4,
"find_key_and_filter_lookup_cost": 6.445451e-4,
"find_key_and_filter_lookup_cost": 7.827422e-4,
"filter_selectivity": 0.021,
"original_rows": 9,
"new_rows": 0.189,
"original_access_cost": 0.011516778,
"with_filter_access_cost": 0.0023698,
"with_filter_access_cost": 0.002507997,
"original_found_rows_cost": 0.010001556,
"with_filter_found_rows_cost": 2.100327e-4,
"org_cost": 0.011804778,
"filter_cost": 0.00267627,
"filter_cost": 0.002814467,
"filter_used": true
},
"access_type": "range",
"range_index": "a",
"rows": 9,
"rows_after_filter": 0.189,
"rows_out": 0.017766,
"cost": 0.00267627,
"cost": 0.002814467,
"chosen": true
}
],
"chosen_access_method": {
"type": "range",
"rows_read": 0.189,
"rows_out": 0.017766,
"cost": 0.00267627,
"cost": 0.002814467,
"uses_join_buffering": false,
"rowid_filter_index": "b"
}
Expand All @@ -12276,7 +12276,7 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
"plan_prefix": "",
"table": "t1",
"rows_for_plan": 0.017766,
"cost_for_plan": 0.00267627,
"cost_for_plan": 0.002814467,
"pushdown_cond_selectivity": 0.094,
"filtered": 0.1974,
"rows_out": 0.017766
Expand All @@ -12286,7 +12286,7 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
{
"best_join_order": ["t1"],
"rows": 0.017766,
"cost": 0.00267627
"cost": 0.002814467
},
{
"table": "t1",
Expand Down Expand Up @@ -12674,20 +12674,20 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
"rowid_filter_index": "b",
"index_only_cost": 0.092006157,
"filter_startup_cost": 0.149564727,
"find_key_and_filter_lookup_cost": 0.085742374,
"find_key_and_filter_lookup_cost": 0.129350121,
"filter_selectivity": 0.4312,
"original_rows": 1000,
"new_rows": 431.2,
"original_access_cost": 1.203290157,
"with_filter_access_cost": 0.656934192,
"with_filter_access_cost": 0.700541939,
"original_found_rows_cost": 1.111284,
"with_filter_found_rows_cost": 0.479185661,
"org_cost": 3.705870471,
"filter_cost": 2.161762502,
"filter_cost": 2.292585745,
"filter_used": true
},
"rows": 431.2,
"cost": 2.161762502,
"cost": 2.292585745,
"chosen": true
},
{
Expand Down
31 changes: 1 addition & 30 deletions mysql-test/main/opt_trace_index_merge.result
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ set optimizer_trace='enabled=on';
# 3-way ROR-intersection
explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref|filter key1,key2,key3 key1|key2 5|5 const 2243 (3%) Using where; Using rowid filter
1 SIMPLE t1 index_merge key1,key2,key3 key1,key2 5,5 NULL 77 Using intersect(key1,key2); Using where
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[
Expand Down Expand Up @@ -423,22 +423,6 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
},
"analyzing_index_merge_union":
[]
},
{
"range_scan_alternatives":
[
{
"index": "key2",
"ranges":
["(100) <= (key2) <= (100)"],
"rowid_ordered": true,
"using_mrr": false,
"index_only": true,
"rows": 2243,
"cost": 0.312832109,
"chosen": true
}
]
}
]
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
Expand Down Expand Up @@ -473,19 +457,6 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
"rows_for_plan": 77,
"cost_for_plan": 0.572490756,
"chosen": true
},
{
"range_access_plan":
{
"type": "range_scan",
"index": "key2",
"rows": 2243,
"ranges":
["(100) <= (key2) <= (100)"]
},
"rows_for_plan": 2243,
"cost_for_plan": 0.312832109,
"chosen": true
}
]
# ROR-union(ROR-intersection, ROR-range)
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/main/optimizer_costs.result
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ OPTIMIZER_DISK_READ_RATIO 0.020000
OPTIMIZER_ROW_COPY_COST 0.060866
OPTIMIZER_ROW_LOOKUP_COST 0.130839
OPTIMIZER_ROW_NEXT_FIND_COST 0.045916
OPTIMIZER_ROWID_COMPARE_COST 0.001000
OPTIMIZER_ROWID_COPY_COST 0.001000
OPTIMIZER_ROWID_COMPARE_COST 0.002653
OPTIMIZER_ROWID_COPY_COST 0.002653
ENGINE default
OPTIMIZER_DISK_READ_COST 10.240000
OPTIMIZER_INDEX_BLOCK_COPY_COST 0.035600
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/main/range.result
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,7 @@ select count(*) from t2 left join t1
on (t1.key1 < 3 or t1.key1 between 920 and 930) and t1.key2 < 1000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 64
1 SIMPLE t1 range|filter i1,i2 i1|i2 4|4 NULL 12 (89%) Using where; Using join buffer (flat, BNL join); Using rowid filter
1 SIMPLE t1 range i1,i2 i1 4 NULL 12 Using where; Using join buffer (flat, BNL join)
select count(*) from t2 left join t1
on (t1.key1 < 3 or t1.key1 between 920 and 930) and t1.key2 < 1000;
count(*)
Expand Down
Loading

0 comments on commit 66dde8a

Please sign in to comment.