Skip to content

Commit 657ff8d

Browse files
committed
[#28616] docdb: optimize index scans by adaptively deciding whether to use next or re-seek
Summary: For index scan scenarios, optimisation to use up to `max_nexts_to_avoid_seek` nexts instead of seek could be useless when main table rows selected by index are not close enough one to each other. This revision adds logic to avoid useless next calls instead of seek using the following approach. If during RocksDB iterator lifetime optimisation was not useful for >= `rocksdb_next_optimization_not_useful_limit` times and useful/num_nexts ratio is less than `rocksdb_next_optimization_skip_threshold_percentage` it stops using next instead of seek for this iterator. That change allowed to reduce `select v3 from t3 where v1 = 123` query latency on serving data from block-cache from ~61ms to ~55ms (~10% improvement) for the following data set: ``` CREATE TABLE t3(k uuid default gen_random_uuid() primary key, v1 bigint, v2 bigint, v3 bigint, v4 varchar, v5 varchar) SPLIT INTO 3 TABLETS; CREATE INDEX ON t3(v1) INCLUDE (v2); WITH config AS ( SELECT 100000000::BIGINT AS total_records, 100000::BIGINT AS chunk_size ) SELECT format( 'INSERT INTO t3(v1,v2,v3,v4,v5) SELECT i %% 20000, i, i, i || repeat(''abcd'',100), i || repeat(''foobar'',100) FROM generate_series(%s, %s) AS i;', (n * chunk_size) + 1, (n + 1) * chunk_size ) FROM generate_series(0, (SELECT total_records / chunk_size - 1 FROM config)) AS n, config \gexec ``` This query uses the index on `v1` and will match/will lookup 5000 rows in the main table. Given that there are 3 tablets for the main table, we retrieve about 1666 rows from each tablet. And the metrics we track to decide whether to avoid the next calls and simply re-seek for each row are maintained in each tablet level request. Jira: DB-18311 Test Plan: Jenkins Reviewers: arybochkin Reviewed By: arybochkin Subscribers: kannan, mihnea, rthallam, ybase Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D46981
1 parent 20b6c63 commit 657ff8d

15 files changed

+407
-285
lines changed

java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgCostModelSeekNextEstimation.java

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ private void testSeekAndNextEstimationBitmapScanHelper(
253253
.nodeType(NODE_YB_BITMAP_TABLE_SCAN)
254254
.relationName(table_name)
255255
.estimatedSeeks(expectedSeeksRange(expected_seeks))
256-
.estimatedNextsAndPrevs(expectedNextsRange(expected_nexts))
256+
// TODO(#28919): Fix cost model to take into account changes in DocDB seek/next behaviour made by
257+
// https://github.com/yugabyte/yugabyte-db/issues/28616 and uncomment this line:
258+
// .estimatedNextsAndPrevs(expectedNextsRange(expected_nexts))
257259
.estimatedDocdbResultWidth(Checkers.equal(expected_docdb_result_width))
258260
.readMetrics(makeMetricsBuilder()
259261
.metric(METRIC_NUM_DB_SEEK, expectedSeeksRange(expected_seeks))
@@ -513,6 +515,7 @@ public void tearDown() throws Exception {
513515
protected Map<String, String> getTServerFlags() {
514516
Map<String, String> flagMap = super.getTServerFlags();
515517
flagMap.put("ysql_analyze_dump_metrics", "true");
518+
flagMap.put("ysql_enable_packed_row", "true");
516519
flagMap.put("ysql_enable_packed_row_for_colocated_table", "true");
517520
// Disable auto analyze for CBO seek and next metrics test.
518521
flagMap.put("ysql_enable_auto_analyze", "false");
@@ -762,58 +765,58 @@ public void testSeekNextEstimationBitmapScan() throws Exception {
762765
T1_NAME, 4, 10, 5, makeBitmapIndexScanChecker(T1_INDEX_NAME, 4, 10));
763766
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
764767
+ "FROM %s WHERE k1 IN (4, 8, 12, 16)", T2_NAME, T2_NAME),
765-
T2_NAME, 80, 240, 10, makeBitmapIndexScanChecker(T2_INDEX_NAME, 4, 86));
768+
T2_NAME, 80, 100, 10, makeBitmapIndexScanChecker(T2_INDEX_NAME, 4, 86));
766769
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
767770
+ "FROM %s WHERE k2 IN (4, 8, 12, 16)", T2_NAME, T2_NAME),
768-
T2_NAME, 80, 240, 10, makeBitmapIndexScanChecker(T2_INDEX_NAME, 101, 280));
771+
T2_NAME, 80, 100, 10, makeBitmapIndexScanChecker(T2_INDEX_NAME, 101, 280));
769772
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
770773
+ "FROM %s WHERE k1 IN (4, 8, 12) AND k4 IN (4, 8, 12, 16)", T4_NAME, T4_NAME),
771-
T4_NAME, 4830, 14490, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 6007, 16808));
774+
T4_NAME, 4800, 4900, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 6007, 16808));
772775
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
773776
+ "FROM %s WHERE k2 IN (4, 8, 12, 16) AND k4 IN (4, 8, 12)", T4_NAME, T4_NAME),
774-
T4_NAME, 4800, 14400, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 6505, 17804));
777+
T4_NAME, 4800, 4900, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 6505, 17804));
775778
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
776779
+ "FROM %s WHERE k1 IN (4, 8, 12, 16) AND k2 IN (4, 8, 12, 16)", T4_NAME, T4_NAME),
777-
T4_NAME, 6400, 19200, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 22, 6436));
780+
T4_NAME, 6400, 6540, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 22, 6436));
778781
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
779782
+ "FROM %s WHERE k1 >= 4 and k1 < 14", T1_NAME, T1_NAME),
780783
T1_NAME, 10, 30, 5, makeBitmapIndexScanChecker(T1_INDEX_NAME, 1, 10));
781784
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
782785
+ "FROM %s WHERE k1 >= 4 and k1 < 14", T2_NAME, T2_NAME),
783-
T2_NAME, 200, 600, 10, makeBitmapIndexScanChecker(T2_INDEX_NAME, 1, 200));
786+
T2_NAME, 200, 220, 10, makeBitmapIndexScanChecker(T2_INDEX_NAME, 1, 200));
784787
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
785788
+ "FROM %s WHERE k1 >= 4 and k1 < 14", T3_NAME, T3_NAME),
786-
T3_NAME, 4000, 12000, 15, makeBitmapIndexScanChecker(T3_INDEX_NAME, 4, 4000));
789+
T3_NAME, 4000, 4080, 15, makeBitmapIndexScanChecker(T3_INDEX_NAME, 4, 4000));
787790
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
788791
+ "FROM %s WHERE k1 >= 4 and k1 < 14", T4_NAME, T4_NAME),
789-
T4_NAME, 80000, 240000, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 79, 80000));
792+
T4_NAME, 80000, 81580, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 79, 80000));
790793
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
791794
+ "FROM %s WHERE k2 >= 4 and k2 < 14", T2_NAME, T2_NAME),
792-
T2_NAME, 200, 600, 10, makeBitmapIndexScanChecker(T2_INDEX_NAME, 41, 280));
795+
T2_NAME, 200, 220, 10, makeBitmapIndexScanChecker(T2_INDEX_NAME, 41, 280));
793796
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
794797
+ "FROM %s WHERE k3 >= 4 and k3 < 14", T3_NAME, T3_NAME),
795-
T3_NAME, 4000, 12000, 15, makeBitmapIndexScanChecker(T3_INDEX_NAME, 804, 5600));
798+
T3_NAME, 4000, 4080, 15, makeBitmapIndexScanChecker(T3_INDEX_NAME, 804, 5600));
796799
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
797800
+ "FROM %s WHERE k4 >= 4 and k4 < 14", T4_NAME, T4_NAME),
798-
T4_NAME, 80000, 240000, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 16079, 112000));
801+
T4_NAME, 80000, 81580, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 16079, 112000));
799802
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
800803
+ "FROM %s WHERE k3 >= 4 and k3 < 14", T4_NAME, T4_NAME),
801-
T4_NAME, 80000, 240000, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 879, 81600));
804+
T4_NAME, 80000, 81580, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 879, 81600));
802805
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
803806
+ "FROM %s WHERE k2 >= 4 and k2 < 14", T4_NAME, T4_NAME),
804-
T4_NAME, 80000, 240000, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 120, 80000));
807+
T4_NAME, 80000, 81580, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 120, 80000));
805808
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
806809
+ "FROM %s WHERE k1 >= 4 and k1 < 14 and k3 >= 4 and k3 < 14", T4_NAME, T4_NAME),
807-
T4_NAME, 40000, 120000, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 440, 40800));
810+
T4_NAME, 40000, 40800, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 440, 40800));
808811
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
809812
+ "FROM %s WHERE k1 = 4 and k2 IN (4, 8, 12, 16)", T4_NAME, T4_NAME),
810-
T4_NAME, 1600, 4800, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 5, 1606));
813+
T4_NAME, 1600, 1640, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 5, 1606));
811814
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
812815
+ "FROM %s WHERE k1 IN (4, 8, 12, 16) and k2 = 4", T4_NAME, T4_NAME),
813-
T4_NAME, 1600, 4800, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 5, 1606));
816+
T4_NAME, 1600, 1640, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 5, 1606));
814817
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
815818
+ "FROM %s WHERE k3 IN (4, 8, 12, 16) and k4 = 4", T4_NAME, T4_NAME),
816-
T4_NAME, 1600, 4800, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 2002, 4000));
819+
T4_NAME, 1600, 1640, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 2002, 4000));
817820
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
818821
+ "FROM %s WHERE k1 >= 4 and k1 < 5 and k2 IN (4, 8, 12, 16)", T2_NAME, T2_NAME),
819822
T2_NAME, 4, 12, 10, makeBitmapIndexScanChecker(T2_INDEX_NAME, 5, 8));
@@ -825,31 +828,31 @@ public void testSeekNextEstimationBitmapScan() throws Exception {
825828
T2_NAME, 40, 120, 10, makeBitmapIndexScanChecker(T2_INDEX_NAME, 50, 98));
826829
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
827830
+ "FROM %s WHERE k1 >= 4 and k1 < 7 and k3 IN (4, 8, 12, 16)", T3_NAME, T3_NAME),
828-
T3_NAME, 240, 720, 15, makeBitmapIndexScanChecker(T3_INDEX_NAME, 301, 600));
831+
T3_NAME, 240, 260, 15, makeBitmapIndexScanChecker(T3_INDEX_NAME, 301, 600));
829832
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
830833
+ "FROM %s WHERE k2 >= 4 and k2 < 7 and k4 IN (4, 8, 12)", T4_NAME, T4_NAME),
831-
T4_NAME, 3600, 10800, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 4844, 9680));
834+
T4_NAME, 3600, 3680, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 4844, 9680));
832835
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
833836
+ "FROM %s WHERE k1 IN (1, 4, 7, 10)", T4_NAME, T4_NAME),
834-
T4_NAME, 32000, 96000, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 35, 32037));
837+
T4_NAME, 32000, 32640, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 35, 32037));
835838
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
836839
+ "FROM %s WHERE k1 >= 4 AND k1 < 14 AND k2 >= 4", T4_NAME, T4_NAME),
837-
T4_NAME, 68000, 204000, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 76, 68084));
840+
T4_NAME, 68000, 69340, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 76, 68084));
838841
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
839842
+ "FROM %s WHERE k1 >= 4 AND k1 < 14 AND k2 >= 4 AND k2 < 14", T4_NAME, T4_NAME),
840-
T4_NAME, 40000, 120000, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 59, 40077));
843+
T4_NAME, 40000, 40802, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 59, 40077));
841844
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
842845
+ "FROM %s WHERE k1 >= 4 AND k2 >= 4 AND k2 < 14", T4_NAME, T4_NAME),
843-
T4_NAME, 68000, 204000, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 100, 68132));
846+
T4_NAME, 68000, 69340, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 100, 68132));
844847
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
845848
+ "FROM %s WHERE k1 IN (1, 4, 7, 10) AND k2 IN (1, 4, 7, 10)", T4_NAME, T4_NAME),
846-
T4_NAME, 6400, 19200, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 22, 6436));
849+
T4_NAME, 6400, 6450, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 22, 6436));
847850
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
848851
+ "FROM %s WHERE k1 >= 4 AND k1 < 14 AND k3 >= 4 AND k3 < 14", T4_NAME, T4_NAME),
849-
T4_NAME, 40000, 120000, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 440, 40839));
852+
T4_NAME, 40000, 40800, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 440, 40839));
850853
testSeekAndNextEstimationBitmapScanHelper(stmt, String.format("/*+BitmapScan(%s)*/ SELECT * "
851854
+ "FROM %s WHERE k1 >= 4 AND k3 >= 4 AND k3 < 14", T4_NAME, T4_NAME),
852-
T4_NAME, 68000, 204000, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 747, 69426));
855+
T4_NAME, 68000, 69340, 20, makeBitmapIndexScanChecker(T4_INDEX_NAME, 747, 69426));
853856
stmt.execute("RESET work_mem");
854857
}
855858
}
@@ -958,12 +961,12 @@ public void testSeekNextEstimationBitmapScanWithAnd() throws Exception {
958961
final String query = "/*+ BitmapScan(t) */ SELECT * FROM %s AS t WHERE %s";
959962
testSeekAndNextEstimationBitmapScanHelper(stmt,
960963
String.format(query, T_NO_PKEY_NAME, "k1 <= 1 AND k2 <= 1"),
961-
T_NO_PKEY_NAME, 100, 300, 10,
964+
T_NO_PKEY_NAME, 100, 120, 10,
962965
makePlanBuilder().nodeType(NODE_BITMAP_INDEX_SCAN).build());
963966

964967
testSeekAndNextEstimationBitmapScanHelper(stmt,
965968
String.format(query, T_NO_PKEY_NAME, "k1 <= 2 AND k2 <= 2"),
966-
T_NO_PKEY_NAME, 200, 600, 10,
969+
T_NO_PKEY_NAME, 200, 220, 10,
967970
makePlanBuilder().nodeType(NODE_BITMAP_INDEX_SCAN).build());
968971

969972
testSeekAndNextEstimationBitmapScanHelper(stmt,
@@ -973,35 +976,35 @@ public void testSeekNextEstimationBitmapScanWithAnd() throws Exception {
973976

974977
testSeekAndNextEstimationBitmapScanHelper(stmt,
975978
String.format(query, T_NO_PKEY_NAME, "k1 <= 10 AND k2 <= 10"),
976-
T_NO_PKEY_NAME, 100, 300, 10,
979+
T_NO_PKEY_NAME, 100, 120, 10,
977980
makePlanBuilder().nodeType(NODE_BITMAP_AND).build());
978981

979982
testSeekAndNextEstimationBitmapScanHelper(stmt,
980983
String.format(query, T_NO_PKEY_NAME, "k1 <= 20 AND k2 <= 20"),
981-
T_NO_PKEY_NAME, 400, 1200, 10,
984+
T_NO_PKEY_NAME, 400, 420, 10,
982985
makePlanBuilder().nodeType(NODE_BITMAP_AND).build());
983986

984987
testSeekAndNextEstimationBitmapScanHelper(stmt,
985988
String.format(query, T_NO_PKEY_NAME, "k1 <= 40 AND k2 <= 40"),
986-
T_NO_PKEY_NAME, 1600, 4800, 10,
989+
T_NO_PKEY_NAME, 1600, 1640, 10,
987990
makePlanBuilder().nodeType(NODE_BITMAP_AND).build());
988991

989992
testSeekAndNextEstimationBitmapScanHelper(stmt,
990993
String.format(query, T_NO_PKEY_NAME, "k1 <= 80 AND k2 <= 80"),
991-
T_NO_PKEY_NAME, 8000, 24000, 10,
994+
T_NO_PKEY_NAME, 8000, 8160, 10,
992995
makePlanBuilder().nodeType(NODE_BITMAP_INDEX_SCAN).build());
993996

994997
// If the two sets of ybctids are not similar sizes, it doesn't make sense
995998
// to collect both sets. Instead, we collect the smaller and filter out
996999
// the larger.
9971000
testSeekAndNextEstimationBitmapScanHelper(stmt,
9981001
String.format(query, T_NO_PKEY_NAME, "k1 <= 20 AND k2 <= 40"),
999-
T_NO_PKEY_NAME, 2000, 6000, 10,
1002+
T_NO_PKEY_NAME, 2000, 2040, 10,
10001003
makePlanBuilder().nodeType(NODE_BITMAP_INDEX_SCAN).indexName(T_K1_INDEX_NAME).build());
10011004

10021005
testSeekAndNextEstimationBitmapScanHelper(stmt,
10031006
String.format(query, T_NO_PKEY_NAME, "k1 <= 20 AND k2 <= 10"),
1004-
T_NO_PKEY_NAME, 1000, 3000, 10,
1007+
T_NO_PKEY_NAME, 1000, 1020, 10,
10051008
makePlanBuilder().nodeType(NODE_BITMAP_INDEX_SCAN).indexName(T_K2_INDEX_NAME).build());
10061009
}
10071010
}

src/yb/docdb/conflict_resolution.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -955,21 +955,21 @@ class StrongConflictChecker {
955955
if (PREDICT_FALSE(!FLAGS_TEST_file_to_dump_keys_checked_for_conflict_in_regular_db.empty())) {
956956
RETURN_NOT_OK(TEST_DumpRegularDbKeyToCheck(intent_key));
957957
}
958-
if (!value_iter_.Initialized()) {
958+
if (!value_iter_->Initialized()) {
959959
auto hybrid_time_file_filter =
960960
FLAGS_docdb_ht_filter_conflict_with_committed ? CreateHybridTimeFileFilter(read_time_)
961961
: nullptr;
962-
value_iter_ = CreateRocksDBIterator(
962+
value_iter_ = OptimizedRocksDbIterator<BoundedRocksDbIterator>(CreateRocksDBIterator(
963963
resolver_.doc_db().regular,
964964
resolver_.doc_db().key_bounds,
965965
BloomFilterOptions::Variable(),
966966
rocksdb::kDefaultQueryId,
967967
hybrid_time_file_filter,
968968
/* iterate_upper_bound = */ nullptr,
969-
rocksdb::CacheRestartBlockKeys::kFalse);
969+
rocksdb::CacheRestartBlockKeys::kFalse));
970970
}
971-
value_iter_.UpdateFilterKey(intent_key, Slice());
972-
const auto* entry = &value_iter_.Seek(intent_key);
971+
value_iter_->UpdateFilterKey(intent_key, Slice());
972+
const auto* entry = &value_iter_->Seek(intent_key);
973973

974974
VLOG_WITH_PREFIX_AND_FUNC(4)
975975
<< "Overwrite; Seek: " << intent_key.ToDebugString() << " ("
@@ -1033,10 +1033,10 @@ class StrongConflictChecker {
10331033
buffer_.Reset(existing_key);
10341034
// Already have ValueType::kHybridTime at the end
10351035
buffer_.AppendHybridTime(DocHybridTime::kMin);
1036-
entry = &ROCKSDB_SEEK(&value_iter_, buffer_.AsSlice());
1036+
entry = &ROCKSDB_SEEK(value_iter_, buffer_.AsSlice());
10371037
}
10381038

1039-
return value_iter_.status();
1039+
return value_iter_->status();
10401040
}
10411041

10421042
private:
@@ -1059,7 +1059,7 @@ class StrongConflictChecker {
10591059
KeyBytes& buffer_;
10601060

10611061
// RocksDb iterator with bloom filter can be reused in case keys has same hash component.
1062-
BoundedRocksDbIterator value_iter_;
1062+
OptimizedRocksDbIterator<BoundedRocksDbIterator> value_iter_;
10631063
};
10641064

10651065
class ConflictResolverContextBase : public ConflictResolverContext {

src/yb/docdb/doc_operation-test.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "yb/common/ql_value.h"
1919
#include "yb/common/transaction-test-util.h"
2020

21+
#include "yb/docdb/bounded_rocksdb_iterator.h"
2122
#include "yb/docdb/cql_operation.h"
2223
#include "yb/docdb/doc_read_context.h"
2324
#include "yb/docdb/doc_rowwise_iterator.h"
@@ -396,8 +397,9 @@ TEST_F(DocOperationTest, TestRedisSetKVWithTTL) {
396397
// Read key from rocksdb.
397398
const auto doc_key = DocKey::FromRedisKey(123, "abc").Encode();
398399
rocksdb::ReadOptions read_opts;
399-
auto iter = std::unique_ptr<rocksdb::Iterator>(db->NewIterator(read_opts));
400-
ROCKSDB_SEEK(iter.get(), doc_key.AsSlice());
400+
auto iter = OptimizedRocksDbIterator<BoundedRocksDbIterator>(
401+
BoundedRocksDbIterator(db, read_opts, &KeyBounds::kNoBounds));
402+
ROCKSDB_SEEK(iter, doc_key.AsSlice());
401403
ASSERT_TRUE(ASSERT_RESULT(iter->CheckedValid()));
402404

403405
// Verify correct ttl.

src/yb/docdb/doc_rowwise_iterator.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ Status DocRowwiseIterator::InitForTableType(
142142
CheckInitOnce();
143143
table_type_ = table_type;
144144
ignore_ttl_ = (table_type_ == TableType::PGSQL_TABLE_TYPE);
145-
RETURN_NOT_OK(InitIterator(BloomFilterOptions::Inactive()));
145+
RETURN_NOT_OK(
146+
InitIterator(BloomFilterOptions::Inactive(), AvoidUselessNextInsteadOfSeek::kFalse));
146147

147148
if (sub_doc_key.empty() || add_table_prefix_to_key) {
148149
dockv::DocKeyEncoder(&row_key_).Schema(*schema_);
@@ -160,7 +161,8 @@ Status DocRowwiseIterator::InitForTableType(
160161

161162
Status DocRowwiseIterator::Init(
162163
const qlexpr::YQLScanSpec& doc_spec, SkipSeek skip_seek,
163-
AllowVariableBloomFilter allow_variable_bloom_filter) {
164+
AllowVariableBloomFilter allow_variable_bloom_filter,
165+
AvoidUselessNextInsteadOfSeek avoid_useless_next_instead_of_seek) {
164166
table_type_ = doc_spec.client_type() == YQL_CLIENT_CQL ? TableType::YQL_TABLE_TYPE
165167
: TableType::PGSQL_TABLE_TYPE;
166168
ignore_ttl_ = table_type_ == TableType::PGSQL_TABLE_TYPE;
@@ -210,7 +212,8 @@ Status DocRowwiseIterator::Init(
210212
allow_variable_bloom_filter));
211213

212214
RETURN_NOT_OK(InitIterator(
213-
scan_choices_->BloomFilterOptions(), doc_spec.QueryId(), CreateFileFilter(doc_spec)));
215+
scan_choices_->BloomFilterOptions(), avoid_useless_next_instead_of_seek, doc_spec.QueryId(),
216+
CreateFileFilter(doc_spec)));
214217

215218
if (!skip_seek) {
216219
if (is_forward_scan_) {
@@ -504,6 +507,7 @@ Result<DocHybridTime> DocRowwiseIterator::GetTableTombstoneTime(Slice root_doc_k
504507

505508
Status DocRowwiseIterator::InitIterator(
506509
const BloomFilterOptions& bloom_filter,
510+
AvoidUselessNextInsteadOfSeek avoid_useless_next_instead_of_seek,
507511
const rocksdb::QueryId query_id,
508512
std::shared_ptr<rocksdb::ReadFileFilter> file_filter) {
509513
if (table_type_ == TableType::PGSQL_TABLE_TYPE) {
@@ -528,7 +532,8 @@ Status DocRowwiseIterator::InitIterator(
528532
read_operation_data_,
529533
file_filter,
530534
nullptr /* iterate_upper_bound */,
531-
FastBackwardScan{use_fast_backward_scan_});
535+
FastBackwardScan{use_fast_backward_scan_},
536+
avoid_useless_next_instead_of_seek);
532537
InitResult();
533538

534539
const auto scan_choices_has_upperbound =

src/yb/docdb/doc_rowwise_iterator.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ class DocRowwiseIterator final : public YQLRowwiseIteratorIf {
7676
// Init QL read scan.
7777
Status Init(
7878
const qlexpr::YQLScanSpec& spec, SkipSeek skip_seek = SkipSeek::kFalse,
79-
AllowVariableBloomFilter allow_variable_bloom_filter = AllowVariableBloomFilter::kFalse);
79+
AllowVariableBloomFilter allow_variable_bloom_filter = AllowVariableBloomFilter::kFalse,
80+
AvoidUselessNextInsteadOfSeek avoid_useless_next_instead_of_seek =
81+
AvoidUselessNextInsteadOfSeek::kFalse);
8082

8183
bool IsFetchedRowStatic() const override;
8284

@@ -175,6 +177,7 @@ class DocRowwiseIterator final : public YQLRowwiseIteratorIf {
175177

176178
Status InitIterator(
177179
const BloomFilterOptions& bloom_filter,
180+
AvoidUselessNextInsteadOfSeek avoid_useless_next_instead_of_seek,
178181
const rocksdb::QueryId query_id = rocksdb::kDefaultQueryId,
179182
std::shared_ptr<rocksdb::ReadFileFilter> file_filter = nullptr);
180183

0 commit comments

Comments
 (0)