From b2800cc16d06790d4582e4611b9a48ddf98b6ebb Mon Sep 17 00:00:00 2001 From: Hamkua Date: Mon, 9 Dec 2024 11:39:10 +0900 Subject: [PATCH 1/4] [CBRD-25542] modify partition pruning to use WHERE_RANGE PRED_EXPR instead of indexptr --- src/query/partition.c | 48 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/query/partition.c b/src/query/partition.c index a031c231743..ccea289b52b 100644 --- a/src/query/partition.c +++ b/src/query/partition.c @@ -2844,6 +2844,8 @@ partition_prune_spec (THREAD_ENTRY * thread_p, val_descr * vd, access_spec_node { int error = NO_ERROR; PRUNING_CONTEXT pinfo; + PRUNING_BITSET pruned; + MATCH_STATUS status = MATCH_NOT_FOUND; if (spec == NULL) { @@ -2887,45 +2889,41 @@ partition_prune_spec (THREAD_ENTRY * thread_p, val_descr * vd, access_spec_node pinfo.spec = spec; pinfo.vd = vd; - if (spec->access == ACCESS_METHOD_SEQUENTIAL || spec->access == ACCESS_METHOD_SEQUENTIAL_RECORD_INFO - || spec->access == ACCESS_METHOD_SEQUENTIAL_PAGE_SCAN || spec->access == ACCESS_METHOD_SEQUENTIAL_SAMPLING_SCAN) + pruningset_init (&pruned, PARTITIONS_COUNT (&pinfo)); + if (pinfo.spec->where_pred != NULL) { - error = partition_prune_heap_scan (&pinfo); - if (error != NO_ERROR) - { - ASSERT_ERROR (); - } + status = partition_match_pred_expr (&pinfo, pinfo.spec->where_pred, &pruned); } - else + + if (pinfo.spec->where_key != NULL) { - if (spec->indexptr == NULL) - { - assert (false); + status = partition_match_pred_expr (&pinfo, pinfo.spec->where_key, &pruned); + } - er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_GENERIC_ERROR, 0); - partition_clear_pruning_context (&pinfo); - return ER_FAILED; - } + if (pinfo.spec->where_range != NULL) + { + status = partition_match_pred_expr (&pinfo, pinfo.spec->where_range, &pruned); + } - if (pinfo.partition_pred->func_regu->type != TYPE_ATTR_ID) + if (status == MATCH_NOT_FOUND) + { + if (pinfo.error_code != NO_ERROR) { - /* In the case of index keys, we will only apply pruning if the partition expression is actually an - * attribute. This is because we will not have expressions in the index key, only attributes (except for - * function and filter indexes which are not handled yet) */ - pinfo.attr_position = -1; + ASSERT_ERROR (); } else { - BTID *btid = &spec->indexptr->btid; - error = partition_get_position_in_key (&pinfo, btid); + pruningset_set_all (&pruned); + error = pruningset_to_spec_list (&pinfo, &pruned); if (error != NO_ERROR) { ASSERT_ERROR (); - partition_clear_pruning_context (&pinfo); - return error; } } - error = partition_prune_index_scan (&pinfo); + } + else + { + error = pruningset_to_spec_list (&pinfo, &pruned); if (error != NO_ERROR) { ASSERT_ERROR (); From 5212f5b37c40d81c4fa82cf553361874b9c6a11f Mon Sep 17 00:00:00 2001 From: Hamkua Date: Tue, 17 Dec 2024 16:31:30 +0900 Subject: [PATCH 2/4] [CBRD-25542] modify the pruning set to compute the intersection instead of overwriting it --- src/query/partition.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/query/partition.c b/src/query/partition.c index ccea289b52b..44130b940fd 100644 --- a/src/query/partition.c +++ b/src/query/partition.c @@ -1517,6 +1517,7 @@ static MATCH_STATUS partition_prune (PRUNING_CONTEXT * pinfo, const REGU_VARIABLE * arg, const PRUNING_OP op, PRUNING_BITSET * pruned) { MATCH_STATUS status = MATCH_NOT_FOUND; + PRUNING_BITSET new_pruned; DB_VALUE val; bool is_value = false; @@ -1543,7 +1544,19 @@ partition_prune (PRUNING_CONTEXT * pinfo, const REGU_VARIABLE * arg, const PRUNI return MATCH_NOT_FOUND; } - status = partition_prune_db_val (pinfo, &val, op, pruned); + if (pruningset_popcount (pruned) != 0) + { + pruningset_init (&new_pruned, PARTITIONS_COUNT (pinfo)); + status = partition_prune_db_val (pinfo, &val, op, &new_pruned); + if (status == MATCH_OK) + { + pruningset_intersect (pruned, &new_pruned); + } + } + else + { + status = partition_prune_db_val (pinfo, &val, op, pruned); + } pr_clear_value (&val); From 4951d36cbcec8ff952cf45bc6c1e093daa846d61 Mon Sep 17 00:00:00 2001 From: Hamkua Date: Mon, 23 Dec 2024 13:49:43 +0900 Subject: [PATCH 3/4] [CBRD-25542] Set MATCH_OK status when partition pruning is applied --- src/query/partition.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/query/partition.c b/src/query/partition.c index c88aa03d667..08363df4bb3 100644 --- a/src/query/partition.c +++ b/src/query/partition.c @@ -1552,6 +1552,13 @@ partition_prune (PRUNING_CONTEXT * pinfo, const REGU_VARIABLE * arg, const PRUNI { pruningset_intersect (pruned, &new_pruned); } + else + { + if (pinfo->error_code == NO_ERROR) + { + status = MATCH_OK; + } + } } else { From 7c52a566d563ffa3b6359b5c5342dd27a40b0764 Mon Sep 17 00:00:00 2001 From: Hamkua Date: Tue, 24 Dec 2024 16:58:04 +0900 Subject: [PATCH 4/4] [CBRD-25542] move pruning bitset intersection logic to partition_prune_spec --- src/query/partition.c | 100 +++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 46 deletions(-) diff --git a/src/query/partition.c b/src/query/partition.c index 08363df4bb3..d469f6a07c7 100644 --- a/src/query/partition.c +++ b/src/query/partition.c @@ -1517,7 +1517,6 @@ static MATCH_STATUS partition_prune (PRUNING_CONTEXT * pinfo, const REGU_VARIABLE * arg, const PRUNING_OP op, PRUNING_BITSET * pruned) { MATCH_STATUS status = MATCH_NOT_FOUND; - PRUNING_BITSET new_pruned; DB_VALUE val; bool is_value = false; @@ -1544,26 +1543,7 @@ partition_prune (PRUNING_CONTEXT * pinfo, const REGU_VARIABLE * arg, const PRUNI return MATCH_NOT_FOUND; } - if (pruningset_popcount (pruned) != 0) - { - pruningset_init (&new_pruned, PARTITIONS_COUNT (pinfo)); - status = partition_prune_db_val (pinfo, &val, op, &new_pruned); - if (status == MATCH_OK) - { - pruningset_intersect (pruned, &new_pruned); - } - else - { - if (pinfo->error_code == NO_ERROR) - { - status = MATCH_OK; - } - } - } - else - { - status = partition_prune_db_val (pinfo, &val, op, pruned); - } + status = partition_prune_db_val (pinfo, &val, op, pruned); pr_clear_value (&val); @@ -2865,7 +2845,7 @@ partition_prune_spec (THREAD_ENTRY * thread_p, val_descr * vd, access_spec_node { int error = NO_ERROR; PRUNING_CONTEXT pinfo; - PRUNING_BITSET pruned; + PRUNING_BITSET pruned, pruned_pred, pruned_key, pruned_range; MATCH_STATUS status = MATCH_NOT_FOUND; if (spec == NULL) @@ -2911,49 +2891,74 @@ partition_prune_spec (THREAD_ENTRY * thread_p, val_descr * vd, access_spec_node pinfo.vd = vd; pruningset_init (&pruned, PARTITIONS_COUNT (&pinfo)); + pruningset_set_all (&pruned); + if (pinfo.spec->where_pred != NULL) { - status = partition_match_pred_expr (&pinfo, pinfo.spec->where_pred, &pruned); - } + pruningset_init (&pruned_pred, PARTITIONS_COUNT (&pinfo)); - if (pinfo.spec->where_key != NULL) - { - status = partition_match_pred_expr (&pinfo, pinfo.spec->where_key, &pruned); + status = partition_match_pred_expr (&pinfo, pinfo.spec->where_pred, &pruned_pred); + if (status == MATCH_NOT_FOUND) + { + if (pinfo.error_code != NO_ERROR) + { + ASSERT_ERROR (); + error = pinfo.error_code; + goto error_exit; + } + } + else + { + pruningset_intersect (&pruned, &pruned_pred); + } } - if (pinfo.spec->where_range != NULL) + if (pinfo.spec->where_key != NULL) { - status = partition_match_pred_expr (&pinfo, pinfo.spec->where_range, &pruned); - } + pruningset_init (&pruned_key, PARTITIONS_COUNT (&pinfo)); - if (status == MATCH_NOT_FOUND) - { - if (pinfo.error_code != NO_ERROR) + status = partition_match_pred_expr (&pinfo, pinfo.spec->where_key, &pruned_key); + if (status == MATCH_NOT_FOUND) { - ASSERT_ERROR (); + if (pinfo.error_code != NO_ERROR) + { + ASSERT_ERROR (); + error = pinfo.error_code; + goto error_exit; + } } else { - pruningset_set_all (&pruned); - error = pruningset_to_spec_list (&pinfo, &pruned); - if (error != NO_ERROR) + pruningset_intersect (&pruned, &pruned_key); + } + } + + if (pinfo.spec->where_range != NULL) + { + pruningset_init (&pruned_range, PARTITIONS_COUNT (&pinfo)); + status = partition_match_pred_expr (&pinfo, pinfo.spec->where_range, &pruned_range); + if (status == MATCH_NOT_FOUND) + { + if (pinfo.error_code != NO_ERROR) { ASSERT_ERROR (); + error = pinfo.error_code; + goto error_exit; } } - } - else - { - error = pruningset_to_spec_list (&pinfo, &pruned); - if (error != NO_ERROR) + else { - ASSERT_ERROR (); + pruningset_intersect (&pruned, &pruned_range); } } - partition_clear_pruning_context (&pinfo); - - if (error == NO_ERROR) + error = pruningset_to_spec_list (&pinfo, &pruned); + if (error != NO_ERROR) + { + ASSERT_ERROR (); + goto error_exit; + } + else { spec->pruned = true; } @@ -2968,6 +2973,9 @@ partition_prune_spec (THREAD_ENTRY * thread_p, val_descr * vd, access_spec_node } } +error_exit: + partition_clear_pruning_context (&pinfo); + return error; }