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

ADBDEV-3929 Fix deadlock by shared SegmentGeneral CTE & planning failure by sharing General CTE #640

Merged
merged 18 commits into from
Dec 11, 2023

Conversation

trexxet2
Copy link

@trexxet2 trexxet2 commented Oct 30, 2023

Depending on the usage of the shared CTE with General or SegmentGeneral
subplan, the number of segments the CTE is executed on may be single for joins
with Singleton nodes, and multiple for nodes with other types of locus. In the
current implementation this may lead to deadlock if the CTE is used for both
join targets: the Join with the Singleton node results in the Share Input Scan
producer being executed with 1-gang, while the Join with the N-gang node
creates Share Input Scan reader on multiple segments, so the plan execution
hangs for the SegmentGeneral, and assertions fail inside
shareinput_mutator_xslice_*() functions for the General. If we force execution
of CTE on multiple segments, it will cause redundant motions in case of
joining the CTE with another General or SegmentGeneral. At the moment of
constructing and sharing the CTE we don't know the rest of the plan, so we
can't predict the correct CTE locus. Because replicated tables are considered
small, the most universal and optimal way to fix deadlock would be to inline
CTE scans with General or SegmentGeneral locus.

Inlining plan is implemented by making the CTE subplan once and then copying
it instead of sharing. This solution, however, cannot push filters down, because
this must be done before building the subplan, and the subplan locus can't be
known before it's construction.

@RekGRpth

This comment was marked as resolved.

@trexxet2
Copy link
Author

the most universal and optimal way to fix deadlock would be to inline CTE scans with SegmentGeneral locus

Does this mean that 7X did not choose the most optimal way to solve the problem?

Yes, 7x makes CTE scan on replicated table on a single segment, shares it and makes Redistribute to spread it across segments:

 Hash Join
   Hash Cond: (share0_ref2.a = share0_ref1.a)
   ->  Limit
         ->  Gather Motion 3:1  (slice1; segments: 3)
               ->  Limit
                     ->  Hash Join
                           Hash Cond: (d.a = share0_ref2.a)
                           ->  Seq Scan on d
                           ->  Hash
                                 ->  Redistribute Motion 1:3  (slice2)
                                       Hash Key: share0_ref2.a
                                       ->  Shared Scan (share slice:id 2:0)
   ->  Hash
         ->  Shared Scan (share slice:id 0:0)
               ->  Aggregate
                     ->  Gather Motion 1:1  (slice3; segments: 1)
                           ->  Seq Scan on r
 Optimizer: Postgres query optimizer
(18 rows)

As I said, the problem is within the nature of Shared Scan - for Joins with Hashed and Singleton we want to perform scan on replicated table on a different subsets of segments, but using Shared Scan we can do it only over a single subset.

src/backend/optimizer/path/allpaths.c Outdated Show resolved Hide resolved
src/test/regress/sql/with.sql Outdated Show resolved Hide resolved
src/test/regress/sql/with.sql Outdated Show resolved Hide resolved
@RekGRpth

This comment was marked as resolved.

@RekGRpth

This comment was marked as resolved.

@KnightMurloc
Copy link

In the PR description, describe in more detail the proposed solution and indicate a known problem (lack of push down filters). also align the description with 80 characters and add the task number to the PR title.

@trexxet2 trexxet2 changed the title Fix deadlock by shared SegmentGeneral CTE ADBDEV-3929 Fix deadlock by shared SegmentGeneral CTE Nov 20, 2023
@KnightMurloc
Copy link

add to the description that inline is implemented by single planning and copying the plan later.

Vyacheslav Kompan added 5 commits November 21, 2023 23:42
Depending on the usage of the shared CTE with SegmentGeneral subplan, the
number of segments the CTE are executed on may be single for joins with
Singleton nodes, and multiple for hashed nodes. In the current implementation
this may lead to deadlock if the CTE is used for both join targets: the Join
with the Singleton node results in the Share Input Scan producer being executed
on a single segment, while the Join with the Hashed node creates
Share Input Scan reader on multiple segments, so the plan execution hangs.
If we force execution of CTE on multiple segments as well, it will cause
redundant motions in case of joining the CTE with another SegmentGeneral.
At the moment of constructing and sharing the CTE we don't know the rest of the
plan, so we can't predict the correct CTE locus. Because replicated tables are
considered small, the most universal and optimal way to fix deadlock would be
to inline CTE scans with SegmentGeneral locus.

This patch fixes the deadlock by disabling sharing CTE if the subplan has
SegmentGeneral locus.
KnightMurloc
KnightMurloc previously approved these changes Nov 23, 2023
src/test/regress/sql/with.sql Outdated Show resolved Hide resolved
src/include/nodes/relation.h Outdated Show resolved Hide resolved
src/backend/optimizer/path/allpaths.c Outdated Show resolved Hide resolved
src/backend/optimizer/path/allpaths.c Show resolved Hide resolved
src/backend/optimizer/path/allpaths.c Show resolved Hide resolved
@BenderArenadata
Copy link

Failed job Regression tests with Postgres on ppc64le: https://gitlab.adsw.io/arenadata/github_mirroring/gpdb/-/jobs/860245

@BenderArenadata
Copy link

Failed job Regression tests with ORCA on ppc64le: https://gitlab.adsw.io/arenadata/github_mirroring/gpdb/-/jobs/860247

@BenderArenadata
Copy link

Failed job Resource group isolation tests on ppc64le: https://gitlab.adsw.io/arenadata/github_mirroring/gpdb/-/jobs/860692

@BenderArenadata
Copy link

Failed job Regression tests with Postgres on ppc64le: https://gitlab.adsw.io/arenadata/github_mirroring/gpdb/-/jobs/860688

@BenderArenadata
Copy link

Failed job Regression tests with Postgres on x86_64: https://gitlab.adsw.io/arenadata/github_mirroring/gpdb/-/jobs/860687

@BenderArenadata
Copy link

Failed job Regression tests with ORCA on ppc64le: https://gitlab.adsw.io/arenadata/github_mirroring/gpdb/-/jobs/860690

@BenderArenadata
Copy link

Failed job Regression tests with ORCA on x86_64: https://gitlab.adsw.io/arenadata/github_mirroring/gpdb/-/jobs/860689

@BenderArenadata
Copy link

Allure report https://allure-ee.adsw.io/launch/59946

@BenderArenadata
Copy link

Failed job Resource group isolation tests on x86_64: https://gitlab.adsw.io/arenadata/github_mirroring/gpdb/-/jobs/861409

@BenderArenadata
Copy link

Failed job Resource group isolation tests on ppc64le: https://gitlab.adsw.io/arenadata/github_mirroring/gpdb/-/jobs/861411

KnightMurloc
KnightMurloc previously approved these changes Dec 7, 2023
RekGRpth
RekGRpth previously approved these changes Dec 8, 2023
@BenderArenadata
Copy link

Allure report https://allure-ee.adsw.io/launch/60061

@BenderArenadata
Copy link

Failed job Resource group isolation tests on x86_64: https://gitlab.adsw.io/arenadata/github_mirroring/gpdb/-/jobs/867698

@BenderArenadata
Copy link

Failed job Resource group isolation tests on ppc64le: https://gitlab.adsw.io/arenadata/github_mirroring/gpdb/-/jobs/867699

@andr-sokolov andr-sokolov merged commit 6cac355 into adb-6.x-dev Dec 11, 2023
3 of 5 checks passed
@andr-sokolov andr-sokolov deleted the ADBDEV-3929 branch December 11, 2023 05:39
@Stolb27 Stolb27 mentioned this pull request Mar 13, 2024
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.

6 participants