Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-25708] Enable partition pruning when the partition key is a function expression and the WHERE clause uses the original column #5682

Open
wants to merge 38 commits into
base: feature/partition-table
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
bf05f66
[CBRD-25708] enable partition pruning when the partition key is a fun…
Hamkua Dec 6, 2024
da0d957
Merge branch 'CUBRID:develop' into CBRD-25708
Hamkua Dec 9, 2024
7f9912a
[CBRD-25708] rename function and reorder conditions
Hamkua Dec 10, 2024
df95b48
[CBRD-25708] only check pruning operator support for arithmetic parti…
Hamkua Dec 10, 2024
53e8727
[CBRD-25708] modify constant value checks to ensure compatibility wit…
Hamkua Dec 10, 2024
b14ecbb
[CBRD-25708] extract logic from partition_match_pred_expr() into sepa…
Hamkua Dec 11, 2024
b6aa622
[CBRD-25708] modify code to ensure successful build
Hamkua Dec 11, 2024
dc69f1e
[CBRD-25708] call partition_supports_pruning_op_for_function() for PR…
Hamkua Dec 11, 2024
dcadf95
Merge branch 'CUBRID:develop' into CBRD-25708
Hamkua Dec 11, 2024
326c529
[CBRD-25708] modify partition pruning to support column in partition …
Hamkua Dec 12, 2024
6803bb8
[CBRD-25708] fix core dump in partition pruning for ALSM operations
Hamkua Dec 13, 2024
ece6758
Merge branch 'CUBRID:develop' into CBRD-25708
Hamkua Dec 13, 2024
bdfa4d6
Merge remote-tracking branch 'upstream/feature/partition-table' into …
Hamkua Dec 19, 2024
ffc2c02
[CBRD-25708] modify to enable partition pruning with collection type …
Hamkua Dec 20, 2024
a006090
[CBRD-25708] temporary implementation of partition pruning for compos…
Hamkua Dec 23, 2024
50a5532
Revert "[CBRD-25708] temporary implementation of partition pruning fo…
Hamkua Dec 26, 2024
96fd4b4
[CBRD-25708] modify partition_do_regu_variable_contain function to fi…
Hamkua Dec 26, 2024
8e04e42
Merge branch 'CUBRID:develop' into CBRD-25708
Hamkua Dec 26, 2024
4dfe2a3
[CBRD-25708] modify DB_VALUE initialization and clearing in each iter…
Hamkua Dec 30, 2024
5b7a7e8
[CBRD-25708] remove unnecessary code
Hamkua Dec 31, 2024
1d5d6cc
[CBRD-25708] revert changes except partition.c
Hamkua Dec 31, 2024
e865566
[CBRD-25708] remove unnecessary changes and clarify function name
Hamkua Dec 31, 2024
018e7b6
[CBRD-25708] add comments
Hamkua Jan 6, 2025
2063173
[CBRD-25708] fix partition pruning to consider all values in ALSM exp…
Hamkua Jan 6, 2025
b4efea6
[CBRD-25708] fix partition pruning to consider all values in ALSM exp…
Hamkua Jan 6, 2025
c85ff5f
[CBRD-25708] add db_make_null to prevent errors on repeated query exe…
Hamkua Jan 6, 2025
7b24d1f
[CBRD-25708] remove unnecessary goto statements in partition_prune_range
Hamkua Jan 6, 2025
9cb18fc
[CBRD-25708] apply code review feedback
Hamkua Jan 6, 2025
7ce3f73
[CBRD-25708] update comment for partition_is_reguvar_const function
Hamkua Jan 13, 2025
3d4d21b
[CBRD-25708] add comments for newly added partition functions
Hamkua Jan 13, 2025
d7a4521
[CBRD-25708] rename partition_prune_arith to partition_prune_for_func…
Hamkua Jan 13, 2025
12bdd5f
[CBRD-25708] store error code in pruning_context and update status
Hamkua Jan 14, 2025
9979bd1
Merge remote-tracking branch 'upstream/feature/partition-table' into …
Hamkua Jan 15, 2025
d5a70e2
[CBRD-25708] apply partition pruning to ELT and INSERT functions
Hamkua Jan 16, 2025
75d5efc
Sync jsp_cl.cpp with upstream/feature/partition-table
Hamkua Jan 16, 2025
465fc9b
[CBRD-25708] restrict partition pruning to integer-returning expressions
Hamkua Jan 22, 2025
11db4d6
[CBRD-25708] modify allowed partition pruning operators
Hamkua Jan 23, 2025
6d3c901
[CBRD-25708] enable partition pruning for IS NULL predicate
Hamkua Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
322 changes: 321 additions & 1 deletion src/query/partition.c

Large diffs are not rendered by default.

198 changes: 198 additions & 0 deletions src/query/query_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,7 @@ qdump_print_access_spec_stats_json (ACCESS_SPEC_TYPE * spec_list_p)
CLS_SPEC_TYPE *cls_node;
ACCESS_SPEC_TYPE *spec;
json_t *scan = NULL, *scan_array = NULL;
json_t *part_scan = NULL, *part_scan_array = NULL;
int num_spec = 0;
char spec_name[1024];
THREAD_ENTRY *thread_p;
Expand Down Expand Up @@ -2961,10 +2962,110 @@ qdump_print_access_spec_stats_json (ACCESS_SPEC_TYPE * spec_list_p)
{
free_and_init (class_name);
}

if (index_name != NULL)
{
free_and_init (index_name);
}

if ((spec->parts != NULL) && (spec->s_id.scan_stats.agl == NULL))
{
PARTITION_SPEC_TYPE *curr_part = NULL, *prev_part = NULL;
SCAN_STATS *scan_stats, *curr_stats, *prev_stats;
SCAN_STATS save_stats;

scan_stats = &spec->s_id.scan_stats;

/* save */
memcpy (&save_stats, &spec->s_id.scan_stats, sizeof (SCAN_STATS));

part_scan_array = json_array ();

for (curr_part = spec->parts; curr_part != NULL; prev_part = curr_part, curr_part = curr_part->next)
{
curr_stats = &curr_part->scan_stats;

if (curr_stats->num_fetches == 0)
{
/* skip */
continue;
}

part_scan = json_object ();

if (heap_get_class_name (thread_p, &curr_part->oid, &class_name) != NO_ERROR)
{
/* ignore */
er_clear ();
}

spec_name[0] = '\0';

switch (spec->access)
{
case ACCESS_METHOD_SEQUENTIAL:
{
if (class_name != NULL)
{
sprintf (spec_name, "table (%s)", class_name);
}
else
{
sprintf (spec_name, "table (unknown)");
}

break;
}

case ACCESS_METHOD_INDEX:
{
if (heap_get_indexinfo_of_btid
(thread_p, &curr_part->oid, &curr_part->btid, NULL, NULL, NULL, NULL, &index_name,
NULL) == NO_ERROR)
{
if (class_name != NULL && index_name != NULL)
{
sprintf (spec_name, "index (%s.%s)", class_name, index_name);
}

else
{
sprintf (spec_name, "index (unknown)");
}
}
break;
}

default:
/* fall through */
break;
}

json_object_set_new (part_scan, "access", json_string (spec_name));

memcpy (scan_stats, &curr_part->scan_stats, sizeof (SCAN_STATS));

/* SCAN_STATS for DB_PARTITION_CLASS does not support AGL (Aggregate Lookup Optimization). */
assert (scan_stats->agl == NULL);

scan_print_stats_json (&spec->s_id, part_scan);

json_array_append_new (part_scan_array, part_scan);

if (class_name != NULL)
{
free_and_init (class_name);
}

if (index_name != NULL)
{
free_and_init (index_name);
}
}

/* restore */
memcpy (&spec->s_id.scan_stats, &save_stats, sizeof (SCAN_STATS));
}
}
else if (type == TARGET_LIST)
{
Expand Down Expand Up @@ -2993,6 +3094,11 @@ qdump_print_access_spec_stats_json (ACCESS_SPEC_TYPE * spec_list_p)

scan_print_stats_json (&spec->s_id, scan);

if (part_scan_array != NULL)
{
json_object_set_new (scan, "PARTITION", part_scan_array);
}

if (scan_array != NULL)
{
json_array_append_new (scan_array, scan);
Expand Down Expand Up @@ -3417,10 +3523,102 @@ qdump_print_access_spec_stats_text (FILE * fp, ACCESS_SPEC_TYPE * spec_list_p, i
{
free_and_init (class_name);
}

if (index_name != NULL)
{
free_and_init (index_name);
}

if ((spec->parts != NULL) && (spec->s_id.scan_stats.agl == NULL))
{
PARTITION_SPEC_TYPE *curr_part = NULL, *prev_part = NULL;
SCAN_STATS *scan_stats, *curr_stats, *prev_stats;
SCAN_STATS save_stats;

scan_stats = &spec->s_id.scan_stats;

/* save */
memcpy (&save_stats, scan_stats, sizeof (SCAN_STATS));

for (curr_part = spec->parts; curr_part != NULL; prev_part = curr_part, curr_part = curr_part->next)
{
curr_stats = &curr_part->scan_stats;

if (curr_stats->num_fetches == 0)
{
/* skip */
continue;
}

fprintf (fp, "\n");
fprintf (fp, "%*cPARTITION ", multi_spec_indent + 2, ' ');

if (heap_get_class_name (thread_p, &curr_part->oid, &class_name) != NO_ERROR)
{
/* ignore */
er_clear ();
}

switch (spec->access)
{
case ACCESS_METHOD_SEQUENTIAL:
{
if (class_name != NULL)
{
fprintf (fp, "(table: %s), ", class_name);
}
else
{
fprintf (fp, "(table: unknown), ");
}

break;
}

case ACCESS_METHOD_INDEX:
{
if (heap_get_indexinfo_of_btid
(thread_p, &curr_part->oid, &curr_part->btid, NULL, NULL, NULL, NULL, &index_name,
NULL) == NO_ERROR)
{
if (class_name != NULL && index_name != NULL)
{
fprintf (fp, "(index: %s.%s), ", class_name, index_name);
}
else
{
fprintf (fp, "(index: unknown), ");
}
}
break;
}

default:
/* fall through */
break;
}

memcpy (scan_stats, &curr_part->scan_stats, sizeof (SCAN_STATS));

/* SCAN_STATS for DB_PARTITION_CLASS does not support AGL (Aggregate Lookup Optimization). */
assert (scan_stats->agl == NULL);

scan_print_stats_text (fp, &spec->s_id);

if (class_name != NULL)
{
free_and_init (class_name);
}

if (index_name != NULL)
{
free_and_init (index_name);
}
}

/* restore */
memcpy (&spec->s_id.scan_stats, &save_stats, sizeof (SCAN_STATS));
}
}
else
{
Expand Down
27 changes: 23 additions & 4 deletions src/query/query_executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -9468,10 +9468,7 @@ qexec_close_scan (THREAD_ENTRY * thread_p, ACCESS_SPEC_TYPE * curr_spec)
/* reset pruning info */
if (curr_spec->type == TARGET_CLASS && curr_spec->parts != NULL)
{
db_private_free (thread_p, curr_spec->parts);
curr_spec->parts = NULL;
curr_spec->curent = NULL;
curr_spec->pruned = false;

/* init btid */
if (curr_spec->indexptr)
Expand Down Expand Up @@ -9685,7 +9682,6 @@ qexec_next_scan_block (THREAD_ENTRY * thread_p, XASL_NODE * xasl)
}
}
while (1);

}

/*
Expand Down Expand Up @@ -10289,6 +10285,28 @@ qexec_init_next_partition (THREAD_ENTRY * thread_p, ACCESS_SPEC_TYPE * spec)
spec->curent = spec->curent->next;
}
}

if (thread_is_on_trace (thread_p))
{
if (spec->curent != NULL)
{
spec->s_id.partition_stats = &spec->curent->scan_stats;

spec->s_id.partition_stats->covered_index = spec->s_id.scan_stats.covered_index;
spec->s_id.partition_stats->multi_range_opt = spec->s_id.scan_stats.multi_range_opt;
spec->s_id.partition_stats->index_skip_scan = spec->s_id.scan_stats.index_skip_scan;
spec->s_id.partition_stats->loose_index_scan = spec->s_id.scan_stats.loose_index_scan;
spec->s_id.partition_stats->noscan = spec->s_id.scan_stats.noscan;

/* SCAN_STATS for DB_PARTITION_CLASS does not support AGL (Aggregate Lookup Optimization). */
spec->s_id.partition_stats->agl = NULL;
}
else
{
spec->s_id.partition_stats = NULL;
}
}

/* close current scan and open a new one on the next partition */
scan_end_scan (thread_p, &spec->s_id);
scan_close_scan (thread_p, &spec->s_id);
Expand Down Expand Up @@ -10444,6 +10462,7 @@ qexec_init_next_partition (THREAD_ENTRY * thread_p, ACCESS_SPEC_TYPE * spec)
{
return S_ERROR;
}

return S_SUCCESS;
}

Expand Down
53 changes: 52 additions & 1 deletion src/query/scan_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -5093,6 +5093,7 @@ scan_next_scan_local (THREAD_ENTRY * thread_p, SCAN_ID * scan_id)
UINT64 old_fetches = 0, old_ioreads = 0;
TSC_TICKS start_tick, end_tick;
TSCTIMEVAL tv_diff;
SCAN_STATS old_scan_stats;

on_trace = thread_is_on_trace (thread_p);
if (on_trace)
Expand All @@ -5101,6 +5102,11 @@ scan_next_scan_local (THREAD_ENTRY * thread_p, SCAN_ID * scan_id)

old_fetches = perfmon_get_from_statistic (thread_p, PSTAT_PB_NUM_FETCHES);
old_ioreads = perfmon_get_from_statistic (thread_p, PSTAT_PB_NUM_IOREADS);

if (scan_id->partition_stats != NULL)
{
memcpy (&old_scan_stats, &scan_id->scan_stats, sizeof (SCAN_STATS));
}
}

switch (scan_id->type)
Expand Down Expand Up @@ -5179,6 +5185,51 @@ scan_next_scan_local (THREAD_ENTRY * thread_p, SCAN_ID * scan_id)

scan_id->scan_stats.num_fetches += perfmon_get_from_statistic (thread_p, PSTAT_PB_NUM_FETCHES) - old_fetches;
scan_id->scan_stats.num_ioreads += perfmon_get_from_statistic (thread_p, PSTAT_PB_NUM_IOREADS) - old_ioreads;

if (scan_id->partition_stats != NULL)
{
perfmon_add_timeval (&scan_id->partition_stats->elapsed_scan, &old_scan_stats.elapsed_scan,
&scan_id->scan_stats.elapsed_scan);
scan_id->partition_stats->num_fetches += scan_id->scan_stats.num_fetches - old_scan_stats.num_fetches;
scan_id->partition_stats->num_ioreads += scan_id->scan_stats.num_ioreads - old_scan_stats.num_ioreads;

switch (scan_id->type)
{
case S_HEAP_SCAN:
case S_HEAP_SCAN_RECORD_INFO:
case S_HEAP_SAMPLING_SCAN:
case S_LIST_SCAN:
scan_id->partition_stats->read_rows += scan_id->scan_stats.read_rows - old_scan_stats.read_rows;
scan_id->partition_stats->qualified_rows +=
scan_id->scan_stats.qualified_rows - old_scan_stats.qualified_rows;
perfmon_add_timeval (&scan_id->partition_stats->elapsed_hash_build, &old_scan_stats.elapsed_hash_build,
&scan_id->scan_stats.elapsed_hash_build);
break;

case S_INDX_SCAN:
scan_id->partition_stats->read_keys += scan_id->scan_stats.read_keys - old_scan_stats.read_keys;
scan_id->partition_stats->qualified_keys +=
scan_id->scan_stats.qualified_keys - old_scan_stats.qualified_keys;
scan_id->partition_stats->key_qualified_rows +=
scan_id->scan_stats.key_qualified_rows - old_scan_stats.key_qualified_rows;
scan_id->partition_stats->data_qualified_rows +=
scan_id->scan_stats.data_qualified_rows - old_scan_stats.data_qualified_rows;
perfmon_add_timeval (&scan_id->partition_stats->elapsed_lookup, &old_scan_stats.elapsed_lookup,
&scan_id->scan_stats.elapsed_lookup);
break;

default:
/* fall through */
break;
}

assert (scan_id->partition_stats->covered_index == scan_id->scan_stats.covered_index);
assert (scan_id->partition_stats->multi_range_opt == scan_id->scan_stats.multi_range_opt);
assert (scan_id->partition_stats->index_skip_scan == scan_id->scan_stats.index_skip_scan);
assert (scan_id->partition_stats->loose_index_scan == scan_id->scan_stats.loose_index_scan);
assert (scan_id->partition_stats->noscan == scan_id->scan_stats.noscan);
assert (scan_id->partition_stats->agl == NULL);
}
}

return status;
Expand Down Expand Up @@ -8056,7 +8107,7 @@ scan_print_stats_text (FILE * fp, SCAN_ID * scan_id)
break;
}
}
#endif
#endif /* SERVER_MODE */

/*
* scan_build_hash_list_scan () - build hash table from list
Expand Down
1 change: 1 addition & 0 deletions src/query/scan_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ struct scan_id_struct
} s;

SCAN_STATS scan_stats;
SCAN_STATS *partition_stats;
bool scan_immediately_stop;
}; /* Scan Identifier */

Expand Down
4 changes: 0 additions & 4 deletions src/query/stream_to_xasl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4690,10 +4690,6 @@ stx_build_access_spec_type (THREAD_ENTRY * thread_p, char *ptr, ACCESS_SPEC_TYPE
}
}

access_spec->parts = NULL;
access_spec->curent = NULL;
access_spec->pruned = false;

ptr = or_unpack_int (ptr, &val);
access_spec->flags = (ACCESS_SPEC_FLAG) val;

Expand Down
1 change: 1 addition & 0 deletions src/query/xasl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,7 @@ struct partition_spec_node
HFID hfid; /* class hfid */
BTID btid; /* index id */
PARTITION_SPEC_TYPE *next; /* next partition */
SCAN_STATS scan_stats;
};
#endif /* defined (SERVER_MODE) || defined (SA_MODE) */

Expand Down
Loading
Loading