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] Avoid unnecessary secondary index writes for UPDATE on table with check constraints #7937

Open
pkj415 opened this issue Apr 6, 2021 · 1 comment
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue

Comments

@pkj415
Copy link
Contributor

pkj415 commented Apr 6, 2021

Jira Link: DB-1356
About single row update optimization - In case of an UPDATE that touches just a single row (and satisfies a few more requirements such as - no check constraints, no triggers, no secondary indexes etc), we have a bunch of optimizations in place (avoiding multi-row transactions, reducing the number of scans, etc).

Avoid Secondary indexes UPDATE optimization - As part of cf94181, updates to unrelated secondary indexes are avoided in UPDATE execution path - when none of the index/included columns of an index are updated by UPDATE statement.

The second optimization above is orthogonal to the idea of single-row optimization - but it is placed in the code path that checks all requirements for single-row optimization. So, there are bugs where the second optimization doesn't come into affect when some requirements of the single row optimization aren't met. Fix this.

@pkj415 pkj415 self-assigned this Apr 6, 2021
@pkj415 pkj415 added the area/ysql Yugabyte SQL (YSQL) label Apr 6, 2021
@pkj415 pkj415 changed the title [YSQL] Avoid unnecessary writes to secondary indexes for multi-row UPDATE [YSQL] Avoid unnecessary writes to secondary indexes for UPDATE with check constraints Apr 8, 2021
@pkj415 pkj415 changed the title [YSQL] Avoid unnecessary writes to secondary indexes for UPDATE with check constraints [YSQL] Avoid unnecessary secondary index writes for UPDATE on table with check constraints Apr 8, 2021
@pkj415
Copy link
Contributor Author

pkj415 commented Apr 12, 2021

Right now, we will only fix the case where secondary index UPDATE optimization is not being performed due to CHECK constraints on the table (a requirement for single row update optimization). [D11223]

Untangling these two optimizations for all other cases - such as in presence of triggers, more than one input sources etc, requires more digging into and carful changes. D11192 was an attempt to do that, but is saved for future.

pkj415 added a commit that referenced this issue Apr 13, 2021
…table with

check constraints

Summary:
To avoid a secondary index update when the indexed/included columns aren't
updated as part of an UPDATE statement, an optimization was made as part of
commit cf94181. However, this optimization is intertwined with the code that
validates requirements for single-row update optimizations. So, for example,
one of the validations is that there should be no CHECK constraints on the table
for the single-row optimization to be performed. So, the secondary index update
optimization doesn't take affect if CHECK constraints are present (even though
CHECK constraints don't matter for this optimization to be valid).

This commit partly fixes this - presence of CHECK constraints won't block
the optimization to avoid secondary index updates when possible.

The correct fix is to untangle these two optimizations, so that they apply
independently always. This is tracked by D11192 and requires more careful
changes.

Test Plan: ybd --java-test org.yb.pgsql.TestPgIndexSelectiveUpdate#testUpdateTableIndexWrites

Reviewers: rskannan, tnayak, mihnea

Reviewed By: mihnea

Subscribers: yql

Differential Revision: https://phabricator.dev.yugabyte.com/D11223
pkj415 added a commit that referenced this issue Apr 15, 2021
…rites for UPDATE on table with check constraints

Summary:
To avoid a secondary index update when the indexed/included columns aren't
updated as part of an UPDATE statement, an optimization was made as part of
commit cf94181. However, this optimization is intertwined with the code that
validates requirements for single-row update optimizations. So, for example,
one of the validations is that there should be no CHECK constraints on the table
for the single-row optimization to be performed. So, the secondary index update
optimization doesn't take affect if CHECK constraints are present (even though
CHECK constraints don't matter for this optimization to be valid).

This commit partly fixes this - presence of CHECK constraints won't block
the optimization to avoid secondary index updates when possible.

The correct fix is to untangle these two optimizations, so that they apply
independently always. This is tracked by D11192 and requires more careful
changes.

Original commit: https://phabricator.dev.yugabyte.com/D11223 / 79e0e12

Test Plan:
ybd --java-test org.yb.pgsql.TestPgIndexSelectiveUpdate#testUpdateTableIndexWrites
Jenkins: rebase: 2.5.3

Reviewers: rskannan, tnayak, mihnea

Reviewed By: mihnea

Subscribers: yql

Differential Revision: https://phabricator.dev.yugabyte.com/D11247
@pkj415 pkj415 closed this as completed May 20, 2021
@pkj415 pkj415 reopened this May 20, 2021
YintongMa pushed a commit to YintongMa/yugabyte-db that referenced this issue May 26, 2021
…DATE on table with

check constraints

Summary:
To avoid a secondary index update when the indexed/included columns aren't
updated as part of an UPDATE statement, an optimization was made as part of
commit cf94181. However, this optimization is intertwined with the code that
validates requirements for single-row update optimizations. So, for example,
one of the validations is that there should be no CHECK constraints on the table
for the single-row optimization to be performed. So, the secondary index update
optimization doesn't take affect if CHECK constraints are present (even though
CHECK constraints don't matter for this optimization to be valid).

This commit partly fixes this - presence of CHECK constraints won't block
the optimization to avoid secondary index updates when possible.

The correct fix is to untangle these two optimizations, so that they apply
independently always. This is tracked by D11192 and requires more careful
changes.

Test Plan: ybd --java-test org.yb.pgsql.TestPgIndexSelectiveUpdate#testUpdateTableIndexWrites

Reviewers: rskannan, tnayak, mihnea

Reviewed By: mihnea

Subscribers: yql

Differential Revision: https://phabricator.dev.yugabyte.com/D11223
@yugabyte-ci yugabyte-ci added kind/bug This issue is a bug priority/medium Medium priority issue labels Jun 8, 2022
@yugabyte-ci yugabyte-ci added kind/enhancement This is an enhancement of an existing feature and removed kind/bug This issue is a bug labels Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue
Projects
Status: No status
Development

No branches or pull requests

2 participants