Skip to content

Check if subpath can do motion.#219

Merged
Stolb27 merged 5 commits into6.17.1_arenadata24from
ADBDEV-1715-2
Aug 6, 2021
Merged

Check if subpath can do motion.#219
Stolb27 merged 5 commits into6.17.1_arenadata24from
ADBDEV-1715-2

Conversation

@InnerLife0
Copy link

@InnerLife0 InnerLife0 commented Jul 1, 2021

UPD: After long debates we decided to do our own fix, which will not be a backport from master branch, because backported commit contains some duplicate logic.

cdbpath_create_motion_path function checks subpath's params Relids, but do it not in place for Bottleneck locus type. When Path contains index scan with quals it leads to segfault.
This PR moves require_existing_order flag analysis higher, before SingleQE and SegmentGeneral, in the place where it really makes sense.
Additionally it adds missed Insist's in the places where we can get NULL value accidentally, and warning message, so we can find what going wrong even on release version.

Additional regression test included.

The info below is obsolete.


cdbpath_create_motion_path function doesn't check subpath's params Relids. When Path contains index scan with quals it leads to segfault.
Fix adds a few additional checks of can motion node be generated atop of subpath. Additional regression test included.
Related to issue #12228. Partial backport of 9cc1da6 (#10012).


Fix is partial, because we don’t need to first bug, mentioned in commit message. We just don’t have some new functions to fix them (add_rowid_to_path). More, regression tests, provided in fix, works well despite of fact orca provides another seems valid plan.


There are functions which ignores NULL value returned by cdbpath_create_motion_path. cdbpath_create_motion_path can already return NULL in several cases, but PR increases the probability of such event. As returning NULL from cdbpath_create_motion_path is not something new and the original commit doesn't contain any additional fixes, we decided to not add NULL value analysis to cdbpath_create_motion_path callers, but rather think about PR and mention it publicly at least.

'cdbpath_create_motion_path' function doesn't check subpath's params Relids. When Path contains index scan with quals it leads to segfault.
Fix adds a few additional checks of can motion node be generated atop of subpath. Additional regression test included.
Related to issue #12228. Partial backport of 9cc1da6 (#10012).
leskin-in
leskin-in previously approved these changes Jul 9, 2021
Copy link

@leskin-in leskin-in left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run pgindent on the code changes.

leskin-in
leskin-in previously approved these changes Jul 12, 2021
Copy link

@leskin-in leskin-in left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run pgindent on the modified code from src/backend/cdb/cdbpath.c.

@InnerLife0
Copy link
Author

Run pgindent on the modified code from src/backend/cdb/cdbpath.c.

Changed TODO comment to pgindent suggestion. The comment above if block left as-is, because it's a part of back-port.

@InnerLife0 InnerLife0 requested a review from leskin-in July 12, 2021 08:01
maksm90
maksm90 previously approved these changes Jul 12, 2021
leskin-in
leskin-in previously approved these changes Jul 12, 2021
@InnerLife0 InnerLife0 dismissed stale reviews from leskin-in and maksm90 via c9b3d00 July 15, 2021 10:35
@Stolb27
Copy link
Collaborator

Stolb27 commented Jul 16, 2021

cdbpath_create_motion_path function doesn't check subpath's params Relids.

@InnerLife0, as we discuss yesterday, this statement is incorrect in common. We pass require_existing_order argument. This flag is checked if subpath for moving contains references to outer relations (here, here and here).

cdbpath_create_motion_path has next contract:

 *    Else if require_existing_order is true, NULL is returned if the
 *      motion would not preserve an ordering at least as strong as the
 *      specified ordering; also NULL is returned if pathkeys is NIL
 *      meaning the caller is just checking and doesn't want to add motion.

and current PR implementation breaks down that. The function must never return NULL if require_existing_order is false.
So insist-checks for function calls that just checking and doesn't want to add motion (NIL in pathkeys and require_existing_order in false) looks redundant.

We may use require_existing_order instead of the current if-condition to save function behavior. This solution eliminates effect to https://github.com/greenplum-db/gpdb/issues/10791. But we need to understand how to process pathkeys for our case.

It seems that we may apply motion to subpath with references to another part of join if pathkeys are provided in the current 6X implementaion.

@maksm90, what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maksm90 I was confused about the type of subpath varaible. It's the argument passed by reference. So in case of condition is true and there is Materialize on top of subpath, we'll remove it anyway after patch.

@InnerLife0
Copy link
Author

New version of PR is available. Please, re-review.

darthunix
darthunix previously approved these changes Jul 21, 2021
darthunix
darthunix previously approved these changes Jul 22, 2021
maksm90
maksm90 previously approved these changes Jul 22, 2021
@Stolb27 Stolb27 mentioned this pull request Aug 3, 2021
5 tasks
@Stolb27
Copy link
Collaborator

Stolb27 commented Aug 4, 2021

@InnerLife0 please rebase this PR on top of adb-6.x. I think we need to revert previous solution (c99892a) as separate commit.

InnerLife0 and others added 2 commits August 4, 2021 14:27
…e. Adding missed blank lines. Mentioning broken regression test.

(cherry picked from commit 3237523)
@InnerLife0 InnerLife0 dismissed stale reviews from maksm90 and darthunix via cf9616b August 4, 2021 09:46
@InnerLife0
Copy link
Author

InnerLife0 commented Aug 4, 2021

Rebased. Commit ebfb060 left as is, as it was already cherry-picked by me to the new PR on the pivotal side. Another commits squashed to one solid solution, which includes removing of our old solution and can be cherry-picked to the mentioned PR.

'if' conditions backported from 9cc1da6 partially duplicates the logic over require_existing_order flag. Instead of applying additional logic, we can move require_existing_order flag analysis higher, before SingleQE and SegmentGeneral, in the place where it really make sense.

Adding additional comments and warning message, so we can find what going wrong even on release version.
Adding missed Insist's to cdbpath_create_motion_path callers.
@Stolb27 Stolb27 changed the base branch from adb-6.x to 6.17.1_arenadata24 August 6, 2021 05:42
@Stolb27 Stolb27 merged commit 1930aab into 6.17.1_arenadata24 Aug 6, 2021
@Stolb27 Stolb27 deleted the ADBDEV-1715-2 branch August 6, 2021 05:45
hilltracer pushed a commit that referenced this pull request Feb 16, 2026
Fix ORCA panic on nonexistent hash opfamilies.

Originally commit 5e04eb1 introduced opfamilies handling and tracking in
CDistributionSpecHashed class. Its code contains PopulateDefaultOpfamilies()
function, which fills opfamily array in cases when it's not passed in ctor.
The initial idea translated by the class was that m_opfamilies must be always
initialized in case of set EopttraceConsiderOpfamiliesForDistribution flag.
However, some specific operations like "parallel union all" are able to work with
data types, which do not have corresponding legacy opclass in GG 6. For example,
these types are arrays (see get_legacy_cdbhash_opclass_for_base_type()
in cdblegacyhash.c), json, etc. And in order to support them in union all cases
commit 47a72cc allowed storing null m_opfamilies by removing an assert in
PopulateDefaultOpfamilies(). That allowed orca to create
CDistributionSpecHashedNoOp for union all without opfamilies. It worked ok
since CDistributionSpecHashedNoOp has it's own matching rules and do not
use opfamilies.

Nevertheless 47a72cc broke the initial concept of not empty opfamilies in
CDistributionSpecHashed and that made some severe errors possible to occur.
In example provided in tests, ORCA faced segfault on accessing the null pointer
(like in CDistributionSpecHashed::FMatchSubset()).

This patch prevents invalid initialization of CDistributionSpecHashed
by adding an exception raise into PopulateDefaultOpfamilies() to preserve
class opfamily invariant. Since we still need specific parallel union all case
to be planned, the ctors of CDistributionSpecHashed are modified to
support CDistributionSpecHashedNoOp case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants