Skip to content

Commit

Permalink
[CBRD-24304] The problem that the optimal plan cannot be found becaus…
Browse files Browse the repository at this point in the history
…e the first node is not properly selected (#3563)

http://jira.cubrid.org/browse/CBRD-24304

modify the first node not to delete up to 10 nodes.
  • Loading branch information
shparkcubrid authored Jun 28, 2022
1 parent 04f3b80 commit 9d59a09
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion src/optimizer/query_planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -8527,7 +8527,7 @@ qo_search_partition_join (QO_PLANNER * planner, QO_PARTITION * partition, BITSET
QO_INFO *r_info, *f_info;
QO_PLAN *r_plan, *f_plan;
PT_NODE *entity;
bool found_f_edge, found_other_edge;
bool found_f_edge, found_other_edge, found_r_edge;
BITSET_ITERATOR bi, bj, bt;
QO_PLAN_COMPARE_RESULT cmp;
BITSET derived_nodes;
Expand Down Expand Up @@ -8557,6 +8557,17 @@ qo_search_partition_join (QO_PLANNER * planner, QO_PARTITION * partition, BITSET
continue; /* OK */
}

/*
* The first node is not excluded up to 10 nodes.
* In fact, the logic to exclude from the first node is not perfect because the cost of index scan is not compared.
* TO_DO : remove routines related to excluding first node
*/
if (nodes_cnt <= 10)
{
bitset_add (&first_nodes, r);
continue; /* OK */
}

if (bitset_is_empty (&first_nodes))
{ /* the first time */
bitset_add (&first_nodes, r);
Expand Down Expand Up @@ -8622,6 +8633,48 @@ qo_search_partition_join (QO_PLANNER * planner, QO_PARTITION * partition, BITSET
}
}

/* check for join-connectivity of r_node to f_node */
found_r_edge = found_other_edge = false; /* init */
for (t = bitset_iterate (&remaining_terms, &bt); t != -1 && !found_other_edge;
t = bitset_next_member (&bt))
{
term = QO_ENV_TERM (env, t);

if (!QO_IS_EDGE_TERM (term))
{
continue;
}

if (!BITSET_MEMBER (QO_TERM_NODES (term), QO_NODE_IDX (r_node)))
{
continue;
}

/* check for f_node's edges */
if (BITSET_MEMBER (QO_TERM_NODES (term), QO_NODE_IDX (f_node)))
{
/* edge between f_node and r_node */

for (i = 0; i < QO_TERM_CAN_USE_INDEX (term) && !found_r_edge; i++)
{
if (QO_NODE_IDX (QO_SEG_HEAD (QO_TERM_INDEX_SEG (term, i))) == QO_NODE_IDX (r_node))
{
found_r_edge = true; /* indexable edge */
}
}
}
else
{
/* edge between f_node and other_node */
found_other_edge = true;
}
}

if (!found_r_edge || found_other_edge)
{
continue; /* do not skip out having other edge or non-inner index scan */
}

/* do not add r_node to the first_nodes */
break;
}
Expand Down

0 comments on commit 9d59a09

Please sign in to comment.