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

[YSQL] INSERT ON CONFLICT read batching stale map can give wrong results #26241

Open
1 task done
jasonyb opened this issue Feb 28, 2025 · 0 comments
Open
1 task done
Labels
2024.2 Backport Required area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue

Comments

@jasonyb
Copy link
Contributor

jasonyb commented Feb 28, 2025

Jira Link: DB-15586

Description

When INSERT ON CONFLICT read batching is used in conjunction with other DMLs within the same statement, the results can be distorted.

Compare the output of the alternate expectfiles of yb.orig.insert_on_conflict_with.out:

and

At it's core, it's a caching issue. Any statements that don't use INSERT ON CONFLICT read batching will not update the INSERT ON CONFLICT maps, both the global intents map (keys that are believed to have been added this executor node) and the batch-read map (keys/slots found existing in the index from this batch's batch read). The above test has simple cases of that using a WITH clause that manipulates the table but does not involve INSERT ON CONFLICT. All DMLs that manipulate the table should also update these maps. Alternatively, the maps should be discarded on such external manipulation, and batching should be restarted with fresh reads.

Commit message a120c25 discusses this issue and a potential solution:

Change the conflict map to be per-plan instead of global. This is
necessary in case we get context-switched out during flushing phase
and interact with the conflict map of a different plan. Keep the
intent set global as we want to detect whether the same row is
inserted twice across plans. Truthfully, such detection should not
be fully global as it should not mix into plans created by triggers,
but that can be loosened in the future. Along the same lines, there
are other deficiencies with the map design such as how it is not
updated when a plan does INSERT, UPDATE, or DELETE without involving
INSERT ON CONFLICT as the map/set alteration only happens within
INSERT ON CONFLICT code. Maybe it is better to go back to design
closer to before 3f2ac8c where the
map/set updates happen in the index INSERT/DELETE/UPDATE paths to
capture all the situations. Push these finer details to be future
work.

Issue Type

kind/bug

Warning: Please confirm that this issue does not contain any sensitive information

  • I confirm this issue does not contain any sensitive information.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2024.2 Backport Required area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

3 participants