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
Changes from 9 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
163 changes: 162 additions & 1 deletion src/query/partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ static MATCH_STATUS partition_match_key_range (PRUNING_CONTEXT * pinfo, const KE
PRUNING_BITSET * pruned);
static bool partition_do_regu_variables_match (PRUNING_CONTEXT * pinfo, const REGU_VARIABLE * left,
const REGU_VARIABLE * right);
static bool partition_do_regu_variables_contain (PRUNING_CONTEXT * pinfo, const REGU_VARIABLE * left,
const REGU_VARIABLE * right);
static MATCH_STATUS partition_prune (PRUNING_CONTEXT * pinfo, const REGU_VARIABLE * arg, const PRUNING_OP op,
PRUNING_BITSET * pruned);
static MATCH_STATUS partition_prune_db_val (PRUNING_CONTEXT * pinfo, const DB_VALUE * val, const PRUNING_OP op,
Expand Down Expand Up @@ -167,6 +169,11 @@ static int partition_attrinfo_get_key (THREAD_ENTRY * thread_p, PRUNING_CONTEXT
/* misc pruning functions */
static bool partition_decrement_value (DB_VALUE * val);

static void partition_cache_dbvalp (REGU_VARIABLE * var, DB_VALUE * val);
Hamkua marked this conversation as resolved.
Show resolved Hide resolved
static bool partition_supports_pruning_op_for_function (const PRUNING_OP op, const REGU_VARIABLE * part_expr);
static MATCH_STATUS partition_prune_arith (PRUNING_CONTEXT * pinfo, const REGU_VARIABLE * left,
Hamkua marked this conversation as resolved.
Show resolved Hide resolved
const REGU_VARIABLE * right, REGU_VARIABLE * part_expr, const PRUNING_OP op,
PRUNING_BITSET * pruned);

/* PRUNING_BITSET manipulation functions */

Expand Down Expand Up @@ -1668,6 +1675,14 @@ partition_is_reguvar_const (const REGU_VARIABLE * regu_var)
/* either all arguments are constants of this is an expression with no arguments */
return true;
}
case TYPE_ATTR_ID:
{
if (regu_var->value.attr_descr.cache_dbvalp == NULL)
shparkcubrid marked this conversation as resolved.
Show resolved Hide resolved
{
return false;
}
return true;
}
default:
return false;
}
Expand Down Expand Up @@ -1910,7 +1925,6 @@ partition_match_pred_expr (PRUNING_CONTEXT * pinfo, const PRED_EXPR * pr, PRUNIN
/* see if part_expr matches right or left */
REGU_VARIABLE *left, *right;
PRUNING_OP op;

Hamkua marked this conversation as resolved.
Show resolved Hide resolved
left = pr->pe.m_eval_term.et.et_comp.lhs;
right = pr->pe.m_eval_term.et.et_comp.rhs;
op = partition_rel_op_to_pruning_op (pr->pe.m_eval_term.et.et_comp.rel_op);
Expand All @@ -1924,6 +1938,17 @@ partition_match_pred_expr (PRUNING_CONTEXT * pinfo, const PRED_EXPR * pr, PRUNIN
{
status = partition_prune (pinfo, left, op, pruned);
}
else if (partition_supports_pruning_op_for_function (op, part_expr))
{
if (partition_do_regu_variables_contain (pinfo, left, part_expr))
{
status = partition_prune_arith (pinfo, left, right, part_expr, op, pruned);
}
else if (partition_do_regu_variables_contain (pinfo, right, part_expr))
{
status = partition_prune_arith (pinfo, right, left, part_expr, op, pruned);
}
}
break;
}

Expand Down Expand Up @@ -1951,6 +1976,13 @@ partition_match_pred_expr (PRUNING_CONTEXT * pinfo, const PRED_EXPR * pr, PRUNIN
{
status = partition_prune (pinfo, list, op, pruned);
}
else if (partition_supports_pruning_op_for_function (op, part_expr))
Hamkua marked this conversation as resolved.
Show resolved Hide resolved
{
if (partition_do_regu_variables_contain (pinfo, regu, part_expr))
{
status = partition_prune_arith (pinfo, regu, list, part_expr, op, pruned);
}
}
}
break;

Expand All @@ -1971,6 +2003,105 @@ partition_match_pred_expr (PRUNING_CONTEXT * pinfo, const PRED_EXPR * pr, PRUNIN
return status;
}

static MATCH_STATUS
shparkcubrid marked this conversation as resolved.
Show resolved Hide resolved
partition_prune_arith (PRUNING_CONTEXT * pinfo, const REGU_VARIABLE * left, const REGU_VARIABLE * right,
REGU_VARIABLE * part_expr, const PRUNING_OP op, PRUNING_BITSET * pruned)
{
MATCH_STATUS status = MATCH_NOT_FOUND;
DB_VALUE val, casted_val;
TP_DOMAIN_STATUS dom_status;
bool is_value;

if (partition_get_value_from_regu_var (pinfo, right, &val, &is_value) == NO_ERROR)
{
if (TP_DOMAIN_TYPE (left->domain) != DB_VALUE_TYPE (&val))
{
dom_status = tp_value_cast (&val, &casted_val, left->domain, false);

if (dom_status != DOMAIN_COMPATIBLE)
{
(void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, &val, left->domain);

pinfo->error_code = ER_FAILED;
pr_clear_value (&val);
pr_clear_value (&casted_val);
return MATCH_NOT_FOUND;
}

partition_cache_dbvalp (part_expr, &casted_val);
}
else
{
partition_cache_dbvalp (part_expr, &val);
}

status = partition_prune (pinfo, part_expr, op, pruned);
partition_cache_dbvalp (part_expr, NULL);
}
pr_clear_value (&val);
pr_clear_value (&casted_val);

return status;
}

static bool
partition_supports_pruning_op_for_function (const PRUNING_OP op, const REGU_VARIABLE * part_expr)
{
OPERATOR_TYPE opcode;

if (part_expr->type != TYPE_INARITH)
Hamkua marked this conversation as resolved.
Show resolved Hide resolved
{
return false;
}

opcode = part_expr->value.arithptr->opcode;

switch (op)
Hamkua marked this conversation as resolved.
Show resolved Hide resolved
{
case PO_LT:
case PO_LE:
case PO_GT:
case PO_GE:
switch (opcode)
{
case T_YEAR:
case T_TODAYS:
case T_UNIX_TIMESTAMP:
return true;
default:
return false;
}
case PO_EQ:
case PO_NE:
case PO_IN:
case PO_NOT_IN:
case PO_IS_NULL:
return true;
default:
return false;
}

}

static bool
partition_do_regu_variables_contain (PRUNING_CONTEXT * pinfo, const REGU_VARIABLE * left, const REGU_VARIABLE * right)
{
if (left == NULL || right == NULL)
{
return left == right;
Hamkua marked this conversation as resolved.
Show resolved Hide resolved
}

if (left->type == TYPE_ATTR_ID && right->type == TYPE_INARITH)
{
if (left->value.attr_descr.id == pinfo->attr_id)
{
return true;
}
}

return false;
}

/*
* partition_match_key_range () - perform pruning using a key_range
* return : pruned list
Expand Down Expand Up @@ -2575,6 +2706,36 @@ partition_set_cache_info_for_expr (REGU_VARIABLE * var, ATTR_ID attr_id, HEAP_CA
}
}

static void
partition_cache_dbvalp (REGU_VARIABLE * var, DB_VALUE * val)
{
assert (var != NULL);
switch (var->type)
{
case TYPE_ATTR_ID:
Hamkua marked this conversation as resolved.
Show resolved Hide resolved
var->value.attr_descr.cache_dbvalp = val;
break;

case TYPE_INARITH:
if (var->value.arithptr->leftptr != NULL)
{
partition_cache_dbvalp (var->value.arithptr->leftptr, val);
}

if (var->value.arithptr->rightptr != NULL)
{
partition_cache_dbvalp (var->value.arithptr->rightptr, val);
}

if (var->value.arithptr->thirdptr != NULL)
{
partition_cache_dbvalp (var->value.arithptr->thirdptr, val);
}
default:
break;
}
}

/*
* partition_get_attribute_id () - get the id of the attribute of the
* partition expression
Expand Down
Loading