Skip to content

Commit

Permalink
[BACKPORT 2024.2][#18152, #18729] Docdb: Fix test TestPgIndexSelectiv…
Browse files Browse the repository at this point in the history
…eUpdate

Summary:
D36588 introduced an optimization to convert updates to included columns of indexes from requiring a DELETE + INSERT RPC to just a single UPDATE RPC.
Furthermore, this optimization allows these index updates to be performed over a single flush to DocDB rather than requiring the previous two.

The reduction in flushes has an impact on the DocDB metric: `intentsdb_rocksdb_write_self` for the index table.
An update to an included column of an index now requires only 2 write batches to be written out to `intentsdb`:
1. The intent to update the column's value. Internal to DocDB/RocksDB, this includes the intents to delete the old value and insert the new value.
2. The intent to delete the intents mentioned in (1) once the operation has been committed to `regulardb`.

Previously, this operation would have needed 3 writes batches:
1. The intent to delete the old value of the column.
2. The intent to insert the new value of the column.
3. The intent to delete the intents mentioned in (1) and (2) once the operation has been committed to `regulardb`.

(1) and (2) were previously distinct because they happened over two separate flushes to DocDB which implies that they were part of two different write batches.

Note - The cases where the metric was previously > 3, was due to the fact that more flushes (> 2) were needed to execute the query. These queries now just need 1 flush.

This revision updates the `org.yb.pgsql.TestPgIndexSelectiveUpdate` with the new expectation for the metric `intentsdb_rocksdb_write_self`.
Jira: DB-7192, DB-7625

Original commit: 6fa33e6 / D38234

Test Plan:
```
./yb_build.sh --java-test 'org.yb.pgsql.TestPgIndexSelectiveUpdate'
```

Reviewers: tnayak

Reviewed By: tnayak

Subscribers: yql, smishra

Tags: #jenkins-ready

Differential Revision: https://phorge.dev.yugabyte.com/D38507
  • Loading branch information
karthik-ramanathan-3006 committed Sep 30, 2024
1 parent c3609d4 commit 076ea48
Showing 1 changed file with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ private void prepareTest(Statement statement) throws Exception {
"CREATE TABLE %s(pk int, col2 int, col3 int, col4 int, col5 int, col6 int, col7 int, "+
"col8 int, col9 int, PRIMARY KEY (pk ASC), CHECK (col4 != 0))", TABLE_NAME));
statement.execute(String.format(
"CREATE INDEX %s on %s(col3 ASC) INCLUDE (col4,col5,col6)", index_list[0], TABLE_NAME));
"CREATE INDEX NONCONCURRENTLY %s on %s(col3 ASC) INCLUDE (col4,col5,col6)",
index_list[0], TABLE_NAME));
statement.execute(String.format(
"CREATE INDEX %s on %s(col5 ASC) INCLUDE (col6,col7)", index_list[1], TABLE_NAME));
"CREATE INDEX NONCONCURRENTLY %s on %s(col5 ASC) INCLUDE (col6,col7)",
index_list[1], TABLE_NAME));
statement.execute(String.format(
"CREATE INDEX %s on %s(col6 ASC) INCLUDE (col9)", index_list[2], TABLE_NAME));
"CREATE INDEX NONCONCURRENTLY %s on %s(col6 ASC) INCLUDE (col9)",
index_list[2], TABLE_NAME));
statement.execute(String.format(
"CREATE INDEX %s on %s(col4 ASC, col5 ASC, col6 ASC)", index_list[3], TABLE_NAME));
"CREATE INDEX NONCONCURRENTLY %s on %s(col4 ASC, col5 ASC, col6 ASC)",
index_list[3], TABLE_NAME));
statement.execute(String.format(
"CREATE INDEX %s on %s(col8 ASC)", index_list[4], TABLE_NAME));
"CREATE INDEX NONCONCURRENTLY %s on %s(col8 ASC)", index_list[4], TABLE_NAME));

// Inserting values into the table
statement.execute(String.format("INSERT INTO %s VALUES (1,1,1,1,1,1,1,1,1)", TABLE_NAME));
Expand Down Expand Up @@ -116,22 +120,22 @@ public void testUpdateTableIndexWrites() throws Exception {
// column 4 is changed. this changes idx_col3, idx_col4_idx_col5_idx_col6.
stmt.execute(String.format("update %s set col4=11 where pk=1", TABLE_NAME));
updateCounter();
checkWrites(3, 0, 0, 3, 0);
checkWrites(2, 0, 0, 2, 0);

// column 6 is changed. this changes idx_col3, idx_col5, idx_col6, idx_col4_idx_col5_idx_col6.
stmt.execute(String.format("update %s set col6=12 where pk=1", TABLE_NAME));
updateCounter();
checkWrites(3, 3, 3, 3, 0);
checkWrites(2, 2, 2, 2, 0);

// column 5 is changed. this changes idx_col3, idx_col5, idx_col4_idx_col5_idx_col6.
stmt.execute(String.format("update %s set col5=13 where pk=1", TABLE_NAME));
updateCounter();
checkWrites(3, 3, 0, 3, 0);
checkWrites(2, 2, 0, 2, 0);

// column 9 is changed. this changes idx_col6.
stmt.execute(String.format("update %s set col9=14 where pk=1", TABLE_NAME));
updateCounter();
checkWrites(0, 0, 3, 0, 0);
checkWrites(0, 0, 2, 0, 0);

// column 2 is changed. this does not affect any index.
stmt.execute(String.format("update %s set col2=15 where pk=1", TABLE_NAME));
Expand All @@ -141,7 +145,7 @@ public void testUpdateTableIndexWrites() throws Exception {
// column 9 is changed for multiple rows.
stmt.execute(String.format("update %s set col9=21 where pk>1", TABLE_NAME));
updateCounter();
checkWrites(0, 0, 7, 0, 0);
checkWrites(0, 0, 2, 0, 0);

// column 8 is changed. No include columns hence just the table and index are updated.
stmt.execute(String.format("update %s set col8=35 where pk=1", TABLE_NAME));
Expand All @@ -150,7 +154,7 @@ public void testUpdateTableIndexWrites() throws Exception {
}
}

/**
/*
* Test index updates with pushdown disabled and non-constant SET clause expressions.
* Not pushable expressions should not prevent index analysis.
*
Expand All @@ -170,22 +174,22 @@ public void testUpdateTableIndexWritesNoPushdown() throws Exception {
// column 4 is changed. this changes idx_col3, idx_col4_idx_col5_idx_col6.
stmt.execute(String.format("update %s set col4=col4+1 where pk=1", TABLE_NAME));
updateCounter();
checkWrites(3, 0, 0, 3, 0);
checkWrites(2, 0, 0, 2, 0);

// column 6 is changed. this changes idx_col3, idx_col5, idx_col6, idx_col4_idx_col5_idx_col6.
stmt.execute(String.format("update %s set col6=col6+1 where pk=1", TABLE_NAME));
updateCounter();
checkWrites(3, 3, 3, 3, 0);
checkWrites(2, 2, 2, 2, 0);

// column 5 is changed. this changes idx_col3, idx_col5, idx_col4_idx_col5_idx_col6.
stmt.execute(String.format("update %s set col5=col5+1 where pk=1", TABLE_NAME));
updateCounter();
checkWrites(3, 3, 0, 3, 0);
checkWrites(2, 2, 0, 2, 0);

// column 9 is changed. this changes idx_col6.
stmt.execute(String.format("update %s set col9=col9+1 where pk=1", TABLE_NAME));
updateCounter();
checkWrites(0, 0, 3, 0, 0);
checkWrites(0, 0, 2, 0, 0);

// column 2 is changed. this does not affect any index.
stmt.execute(String.format("update %s set col2=col2+1 where pk=1", TABLE_NAME));
Expand All @@ -195,7 +199,7 @@ public void testUpdateTableIndexWritesNoPushdown() throws Exception {
// column 9 is changed for multiple rows.
stmt.execute(String.format("update %s set col9=col9+1 where pk>1", TABLE_NAME));
updateCounter();
checkWrites(0, 0, 7, 0, 0);
checkWrites(0, 0, 2, 0, 0);

// column 8 is changed. No include columns hence just the table and index are updated.
stmt.execute(String.format("update %s set col8=col8+1 where pk=1", TABLE_NAME));
Expand Down

0 comments on commit 076ea48

Please sign in to comment.