Skip to content

Commit

Permalink
[yugabyte#18822] YSQL: Enable optimization to skip redundant update o…
Browse files Browse the repository at this point in the history
…perations in 2024.2 by default

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)

This revision turns on the feature by default in 2024.2 by turning ON the feature enablement flag `ysql_yb_skip_redundant_update_ops`.

Jira: DB-7701

Test Plan: Run Jenkins

Reviewers: smishra, amartsinchyk

Reviewed By: smishra

Subscribers: yql, ybase

Tags: #jenkins-ready

Differential Revision: https://phorge.dev.yugabyte.com/D38936
  • Loading branch information
karthik-ramanathan-3006 committed Oct 11, 2024
1 parent 9c21eb1 commit 92e026f
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 @@ -2661,7 +2661,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 @@ -1392,7 +1392,7 @@ int yb_insert_on_conflict_read_batch_size = 1024;

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 @@ -232,7 +232,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 92e026f

Please sign in to comment.