|
64 | 64 | #include "storage/segment/test_segment_writer.h" |
65 | 65 | #include "storage/tablet/tablet_schema_helper.h" |
66 | 66 | #include "storage/utils.h" |
| 67 | +#include "util/debug_points.h" |
67 | 68 |
|
68 | 69 | namespace doris::segment_v2 { |
69 | 70 | namespace { |
@@ -385,6 +386,8 @@ class SegmentIteratorExprZonemapTest : public testing::Test { |
385 | 386 | } |
386 | 387 |
|
387 | 388 | void TearDown() override { |
| 389 | + DebugPoints::instance()->clear(); |
| 390 | + config::enable_debug_points = false; |
388 | 391 | ExecEnv::GetInstance()->set_inverted_index_searcher_cache(_previous_searcher_cache); |
389 | 392 | ExecEnv::GetInstance()->set_inverted_index_query_cache(_previous_query_cache); |
390 | 393 | _inverted_index_searcher_cache.reset(); |
@@ -1622,6 +1625,92 @@ TEST_F(SegmentIteratorExprZonemapTest, RangeVersionIgnoresPlaceholderInvertedInd |
1622 | 1625 | EXPECT_EQ(0, _stats.rows_inverted_index_filtered); |
1623 | 1626 | } |
1624 | 1627 |
|
| 1628 | +TEST_F(SegmentIteratorExprZonemapTest, RangeVersionSkipsPlaceholderProbeWhenIndexQueriesDisabled) { |
| 1629 | + // Case: the query disables inverted index queries, so no predicate consumes the index. The |
| 1630 | + // initialization-time placeholder probe must not query it either. The debug point turns any |
| 1631 | + // index query into a downgrade, so a probe that still runs is visible in the counter. |
| 1632 | + std::shared_ptr<Segment> segment; |
| 1633 | + ASSERT_NO_FATAL_FAILURE(build_version_segment_with_placeholder_index(&segment)); |
| 1634 | + auto read_schema = make_read_schema(_tablet_schema); |
| 1635 | + |
| 1636 | + TQueryOptions query_options; |
| 1637 | + query_options.__set_enable_inverted_index_query(false); |
| 1638 | + query_options.__set_enable_inverted_index_query_cache(false); |
| 1639 | + query_options.__set_enable_inverted_index_searcher_cache(false); |
| 1640 | + _runtime_state.set_query_options(query_options); |
| 1641 | + |
| 1642 | + auto predicate = make_version_eq_column_predicate(kVersionCid, kRangeEndVersion); |
| 1643 | + auto block_predicate = AndBlockColumnPredicate::create_shared(); |
| 1644 | + block_predicate->add_column_predicate(SingleColumnBlockPredicate::create_unique(predicate)); |
| 1645 | + |
| 1646 | + const std::set<int32_t> output_column_uids {0, kVersionCid}; |
| 1647 | + StorageReadOptions read_options(_stats); |
| 1648 | + read_options.runtime_state = &_runtime_state; |
| 1649 | + read_options.version = Version(kRangeStartVersion, kRangeEndVersion); |
| 1650 | + read_options.block_row_max = 1024; |
| 1651 | + read_options.column_predicates = {predicate}; |
| 1652 | + read_options.col_id_to_predicates.emplace(kVersionCid, std::move(block_predicate)); |
| 1653 | + read_options.output_columns = &output_column_uids; |
| 1654 | + |
| 1655 | + config::enable_debug_points = true; |
| 1656 | + DebugPoints::instance()->add("return_inverted_index_bypass"); |
| 1657 | + |
| 1658 | + std::unique_ptr<RowwiseIterator> iter; |
| 1659 | + auto st = segment->new_iterator(read_schema, read_options, &iter); |
| 1660 | + ASSERT_TRUE(st.ok()) << st; |
| 1661 | + ASSERT_NE(nullptr, iter); |
| 1662 | + ASSERT_NO_FATAL_FAILURE(assert_hidden_column_values(iter.get(), read_options, read_schema, |
| 1663 | + kNumRows / 2, kRangeEndVersion)); |
| 1664 | + EXPECT_EQ(0, _stats.inverted_index_downgrade_count); |
| 1665 | +} |
| 1666 | + |
| 1667 | +TEST_F(SegmentIteratorExprZonemapTest, RangeVersionDropsIndexWhenPlaceholderProbeFails) { |
| 1668 | + // Case: the probe cannot answer, as a damaged index leaf does. The intact `[0, 0]` bounds of |
| 1669 | + // the placeholder index would still answer `VERSION = 3` with no rows, so the failed probe |
| 1670 | + // must drop the iterator; the predicate then evaluates the stored values. |
| 1671 | + std::shared_ptr<Segment> segment; |
| 1672 | + ASSERT_NO_FATAL_FAILURE(build_version_segment_with_placeholder_index(&segment)); |
| 1673 | + auto read_schema = make_read_schema(_tablet_schema); |
| 1674 | + |
| 1675 | + TQueryOptions query_options; |
| 1676 | + query_options.__set_enable_inverted_index_query(true); |
| 1677 | + query_options.__set_enable_inverted_index_query_cache(false); |
| 1678 | + query_options.__set_enable_inverted_index_searcher_cache(false); |
| 1679 | + query_options.__set_inverted_index_skip_threshold(0); |
| 1680 | + _runtime_state.set_query_options(query_options); |
| 1681 | + |
| 1682 | + auto predicate = make_version_eq_column_predicate(kVersionCid, kRangeEndVersion); |
| 1683 | + auto block_predicate = AndBlockColumnPredicate::create_shared(); |
| 1684 | + block_predicate->add_column_predicate(SingleColumnBlockPredicate::create_unique(predicate)); |
| 1685 | + |
| 1686 | + const std::set<int32_t> output_column_uids {0, kVersionCid}; |
| 1687 | + StorageReadOptions read_options(_stats); |
| 1688 | + read_options.runtime_state = &_runtime_state; |
| 1689 | + read_options.version = Version(kRangeStartVersion, kRangeEndVersion); |
| 1690 | + read_options.block_row_max = 1024; |
| 1691 | + read_options.column_predicates = {predicate}; |
| 1692 | + read_options.col_id_to_predicates.emplace(kVersionCid, std::move(block_predicate)); |
| 1693 | + read_options.output_columns = &output_column_uids; |
| 1694 | + |
| 1695 | + // The probe runs during init; make its index query return the downgrade status a damaged |
| 1696 | + // index reports, then restore the normal path before the first batch evaluates the predicate. |
| 1697 | + config::enable_debug_points = true; |
| 1698 | + DebugPoints::instance()->add("return_inverted_index_bypass"); |
| 1699 | + std::unique_ptr<RowwiseIterator> iter; |
| 1700 | + auto st = segment->new_iterator(read_schema, read_options, &iter); |
| 1701 | + ASSERT_TRUE(st.ok()) << st; |
| 1702 | + ASSERT_NE(nullptr, iter); |
| 1703 | + st = iter->init(read_options); |
| 1704 | + ASSERT_TRUE(st.ok()) << st; |
| 1705 | + DebugPoints::instance()->remove("return_inverted_index_bypass"); |
| 1706 | + config::enable_debug_points = false; |
| 1707 | + |
| 1708 | + ASSERT_FALSE(iter->empty()); |
| 1709 | + ASSERT_NO_FATAL_FAILURE(assert_hidden_column_values(iter.get(), read_options, read_schema, |
| 1710 | + kNumRows / 2, kRangeEndVersion)); |
| 1711 | + EXPECT_EQ(1, _stats.inverted_index_downgrade_count); |
| 1712 | +} |
| 1713 | + |
1625 | 1714 | TEST_F(SegmentIteratorExprZonemapTest, ExprZonemapUsesReadTimeVersion) { |
1626 | 1715 | constexpr int64_t kVersion = 7; |
1627 | 1716 | _tablet_schema = make_version_tablet_schema(); |
|
0 commit comments