diff --git a/src/query/partition.c b/src/query/partition.c index c104bd0256..d469f6a07c 100644 --- a/src/query/partition.c +++ b/src/query/partition.c @@ -2845,6 +2845,8 @@ partition_prune_spec (THREAD_ENTRY * thread_p, val_descr * vd, access_spec_node { int error = NO_ERROR; PRUNING_CONTEXT pinfo; + PRUNING_BITSET pruned, pruned_pred, pruned_key, pruned_range; + MATCH_STATUS status = MATCH_NOT_FOUND; if (spec == NULL) { @@ -2888,54 +2890,75 @@ 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)); + pruningset_set_all (&pruned); + + if (pinfo.spec->where_pred != NULL) { - error = partition_prune_heap_scan (&pinfo); - if (error != NO_ERROR) + pruningset_init (&pruned_pred, PARTITIONS_COUNT (&pinfo)); + + status = partition_match_pred_expr (&pinfo, pinfo.spec->where_pred, &pruned_pred); + if (status == MATCH_NOT_FOUND) { - ASSERT_ERROR (); + if (pinfo.error_code != NO_ERROR) + { + ASSERT_ERROR (); + error = pinfo.error_code; + goto error_exit; + } } - } - else - { - if (spec->indexptr == NULL) + else { - assert (false); - - er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_GENERIC_ERROR, 0); - partition_clear_pruning_context (&pinfo); - return ER_FAILED; + pruningset_intersect (&pruned, &pruned_pred); } + } - if (pinfo.partition_pred->func_regu->type != TYPE_ATTR_ID) + if (pinfo.spec->where_key != NULL) + { + pruningset_init (&pruned_key, PARTITIONS_COUNT (&pinfo)); + + status = partition_match_pred_expr (&pinfo, pinfo.spec->where_key, &pruned_key); + if (status == MATCH_NOT_FOUND) { - /* 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; + if (pinfo.error_code != NO_ERROR) + { + ASSERT_ERROR (); + error = pinfo.error_code; + goto error_exit; + } } else { - BTID *btid = &spec->indexptr->btid; - error = partition_get_position_in_key (&pinfo, btid); - 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 (); - partition_clear_pruning_context (&pinfo); - return error; + error = pinfo.error_code; + goto error_exit; } } - error = partition_prune_index_scan (&pinfo); - 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; } @@ -2950,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; }