Skip to content

Commit

Permalink
[BACKPORT 2024.2][#18822] YSQL: Re-enable feature to skip redundant i…
Browse files Browse the repository at this point in the history
…ndex updates

Summary:
Timeline:

D34040 introduced an optimization to skip redundant index updates and foreign key checks.
D37746 gated this feature behind a preview flag (feature is OFF by default) named yb_update_optimization_infra.
D37749 introduced a feature enablement flag ysql_yb_skip_redundant_update_ops, and promoted the above preview flag to an auto flag.
D38598 backported the changes of D37749 to 2024.2, while keeping the feature enablement flag turned OFF (the flag is on in master, by default).
D38936 turned ON the feature in 2024.2 via the enablement flag ysql_yb_skip_redundant_update_ops.
D40300 (and its backports) turned OFF the feature via the enablement flag ysql_yb_skip_redundant_update_ops due to the bug GH-25075.
D40404 (and its backports) fixed the above bug.

This revision turns ON the feature by default by turning ON the feature enablement flag ysql_yb_skip_redundant_update_ops.
This reverts commit 0529391 (D40300).
Jira: DB-7701

Original commit: 3c8a0c5 / D40649

Test Plan: Run Jenkins

Reviewers: amartsinchyk, smishra

Reviewed By: smishra

Subscribers: yql, ybase

Tags: #jenkins-ready

Differential Revision: https://phorge.dev.yugabyte.com/D40830
  • Loading branch information
karthik-ramanathan-3006 committed Dec 23, 2024
1 parent 3977a04 commit 8bda14f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ public void testOnConflict() throws Exception {
.plans(resultNodeChecker
.storageTableReadRequests(Checkers.equal(1))
.storageTableWriteRequests(Checkers.equal(1))
.storageIndexWriteRequests(Checkers.equal(TEST_NUM_SEC_INDEXES))
.build())
.build())
.storageFlushRequests(Checkers.equal(1))
Expand Down Expand Up @@ -304,15 +303,15 @@ public void testOnConflict() throws Exception {
{
Checker checker = topLevelChecker
.plan(insertNodeChecker
.plans(resultNodeChecker
.plans(makePlanBuilder()
.nodeType(NODE_RESULT)
.storageTableReadRequests(Checkers.equal(1))
.storageTableWriteRequests(Checkers.equal(1))
.storageIndexWriteRequests(Checkers.equal(TEST_NUM_SEC_INDEXES * 2))
.build())
.build())
.storageFlushRequests(Checkers.equal(2))
.storageFlushRequests(Checkers.equal(1))
.storageReadRequests(Checkers.equal(1))
.storageWriteRequests(Checkers.equal((TEST_NUM_SEC_INDEXES * 2) + 1))
.storageWriteRequests(Checkers.equal(1))
.build();

testExplain(String.format(insertWithOnConflict, TEST_TABLE, "(1, 1, 1, 1, 1)", "k",
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/utils/misc/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2683,7 +2683,7 @@ static struct config_bool ConfigureNamesBool[] =
GUC_NOT_IN_SAMPLE
},
&yb_update_optimization_options.is_enabled,
false,
true,
NULL, NULL, NULL
},

Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/utils/misc/pg_yb_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ bool yb_enable_nop_alter_role_optimization = true;

YBUpdateOptimizationOptions yb_update_optimization_options = {
.has_infra = true,
.is_enabled = false,
.is_enabled = true,
.num_cols_to_compare = 50,
.max_cols_size_to_compare = 10 * 1024
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ PREPARE t2(int) AS UPDATE np SET d = 1 FROM lp WHERE lp.a = np.a AND lp.a = $1;
EXPLAIN EXECUTE t2(1);
QUERY PLAN
---------------------------------------------------------------------------------------------------
Update on np (cost=0.00..232.80 rows=1000000 width=140)
-> Nested Loop (cost=0.00..232.80 rows=1000000 width=140)
-> Seq Scan on np (cost=0.00..102.50 rows=1000 width=72)
Update on np (cost=0.00..232.80 rows=1000000 width=236)
-> Nested Loop (cost=0.00..232.80 rows=1000000 width=236)
-> Seq Scan on np (cost=0.00..102.50 rows=1000 width=168)
Storage Filter: (a = 1)
-> Materialize (cost=0.00..5.32 rows=10 width=40)
-> Append (cost=0.00..5.27 rows=10 width=40)
Expand All @@ -72,9 +72,9 @@ EXPLAIN EXECUTE t2(1);
EXPLAIN EXECUTE t2(1);
QUERY PLAN
---------------------------------------------------------------------------------------------------
Update on np (cost=0.00..232.80 rows=1000000 width=140)
-> Nested Loop (cost=0.00..232.80 rows=1000000 width=140)
-> Seq Scan on np (cost=0.00..102.50 rows=1000 width=72)
Update on np (cost=0.00..232.80 rows=1000000 width=236)
-> Nested Loop (cost=0.00..232.80 rows=1000000 width=236)
-> Seq Scan on np (cost=0.00..102.50 rows=1000 width=168)
Storage Filter: (a = 1)
-> Materialize (cost=0.00..5.32 rows=10 width=40)
-> Append (cost=0.00..5.27 rows=10 width=40)
Expand Down
18 changes: 9 additions & 9 deletions src/postgres/src/test/regress/expected/yb_pg_update.out
Original file line number Diff line number Diff line change
Expand Up @@ -718,25 +718,25 @@ INSERT INTO parted VALUES (1, '1'), (2, '2'), (4, '4'), (6, '6'), (8, '8');
-- Test whether single row optimization is invoked when
-- only one partition is being updated.
EXPLAIN UPDATE parted SET b='5' WHERE a = 1;
QUERY PLAN
-----------------------------------------------------
Update on parted (cost=0.00..4.11 rows=1 width=68)
QUERY PLAN
------------------------------------------------------
Update on parted (cost=0.00..4.11 rows=1 width=128)
Update on part_a_1_5 parted
-> Result (cost=0.00..4.11 rows=1 width=68)
-> Result (cost=0.00..4.11 rows=1 width=128)
(3 rows)

UPDATE parted SET b='5' WHERE a = 1;
-- Verify that single row optimization is not invoked when
-- multiple partitions are being updated.
EXPLAIN UPDATE parted SET b='6' WHERE a > 1;
QUERY PLAN
-----------------------------------------------------------------------
Update on parted (cost=0.00..205.00 rows=2000 width=68)
QUERY PLAN
------------------------------------------------------------------------
Update on parted (cost=0.00..205.00 rows=2000 width=128)
Update on part_a_1_5
Update on part_a_5_10
-> Seq Scan on part_a_1_5 (cost=0.00..102.50 rows=1000 width=68)
-> Seq Scan on part_a_1_5 (cost=0.00..102.50 rows=1000 width=128)
Storage Filter: (a > 1)
-> Seq Scan on part_a_5_10 (cost=0.00..102.50 rows=1000 width=68)
-> Seq Scan on part_a_5_10 (cost=0.00..102.50 rows=1000 width=128)
Storage Filter: (a > 1)
(7 rows)

Expand Down
2 changes: 1 addition & 1 deletion src/yb/common/common_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ DEFINE_RUNTIME_AUTO_PG_FLAG(bool, yb_update_optimization_infra, kLocalPersisted,
"(but not limited to) skipping redundant secondary index updates "
"and redundant constraint checks.");

DEFINE_RUNTIME_PG_FLAG(bool, yb_skip_redundant_update_ops, false,
DEFINE_RUNTIME_PG_FLAG(bool, yb_skip_redundant_update_ops, true,
"Enables the comparison of old and new values of columns specified in the "
"SET clause of YSQL UPDATE queries to skip redundant secondary index "
"updates and redundant constraint checks.");
Expand Down

0 comments on commit 8bda14f

Please sign in to comment.