@@ -70,8 +70,6 @@ class PgDocSampleOp : public PgDocReadOp {
70
70
uint64_t num_blocks_collected;
71
71
double num_rows_processed;
72
72
int32 num_rows_collected;
73
- // TODO(analyze_sampling): https://github.com/yugabyte/yugabyte-db/issues/26366: Remove this:
74
- double DEPRECATED_estimated_total_rows;
75
73
};
76
74
77
75
PgDocSampleOp (const PgSession::ScopedRefPtr& pg_session, PgTable* table, PgsqlReadOpPtr read_op)
@@ -163,10 +161,6 @@ class PgDocSampleOp : public PgDocReadOp {
163
161
.num_blocks_collected = sampling_state->num_blocks_collected (),
164
162
.num_rows_processed = sampling_state->samplerows (),
165
163
.num_rows_collected = sampling_state->numrows (),
166
- // TODO(analyze_sampling): https://github.com/yugabyte/yugabyte-db/issues/26366: Remove this:
167
- .DEPRECATED_estimated_total_rows = sampling_state->has_deprecated_estimated_total_rows ()
168
- ? sampling_state->deprecated_estimated_total_rows ()
169
- : sampling_state->samplerows ()
170
164
};
171
165
172
166
RETURN_NOT_OK (PgDocReadOp::CompleteProcessResponse ());
@@ -611,9 +605,7 @@ class SampleRowsPicker : public SamplePickerBase, public SampleRowsPickerIf {
611
605
}
612
606
613
607
double GetEstimatedRowCount () const override {
614
- // TODO(analyze_sampling): https://github.com/yugabyte/yugabyte-db/issues/26366: Simplify the
615
- // following code to return GetSampleOp().GetSamplingStats().num_rows_processed.
616
- return GetSampleOp ().GetSamplingStats ().DEPRECATED_estimated_total_rows ;
608
+ return GetSampleOp ().GetSamplingStats ().num_rows_processed ;
617
609
}
618
610
619
611
Status SetSampleBlocksBounds (std::vector<std::pair<KeyBuffer, KeyBuffer>>&& sample_blocks) {
@@ -686,6 +678,9 @@ class TwoStageSampleRowsPicker : public SampleRowsPickerIf {
686
678
687
679
double GetEstimatedRowCount () const override {
688
680
const auto num_rows_processed = sample_rows_picker_->GetNumRowsProcessed ();
681
+ VLOG_WITH_FUNC (1 ) << " num_rows_processed: " << num_rows_processed
682
+ << " num_blocks_collected_: " << num_blocks_collected_
683
+ << " num_blocks_processed_: " << num_blocks_processed_;
689
684
return num_blocks_collected_ >= num_blocks_processed_
690
685
? num_rows_processed
691
686
: 1.0 * num_rows_processed * num_blocks_processed_ / num_blocks_collected_;
@@ -743,34 +738,22 @@ Status PgSample::Prepare(
743
738
target_ = PgTable (VERIFY_RESULT (pg_session_->LoadTable (table_id)));
744
739
bind_ = PgTable (nullptr );
745
740
746
- const auto allow_separate_requests_for_sampling_stages =
747
- yb_allow_separate_requests_for_sampling_stages;
748
-
749
- // TODO(analyze_sampling): https://github.com/yugabyte/yugabyte-db/issues/26366:
750
- // Simplify the following code to fallback to YsqlSamplingAlgorithm::FULL_TABLE_SCAN when
751
- // yb_allow_separate_requests_for_sampling_stages is false.
752
741
YsqlSamplingAlgorithm ysql_sampling_algorithm;
753
- if (yb_allow_block_based_sampling_algorithm &&
754
- (target_->IsColocated () || allow_separate_requests_for_sampling_stages)) {
742
+ if (yb_allow_separate_requests_for_sampling_stages) {
755
743
ysql_sampling_algorithm = YsqlSamplingAlgorithm (yb_sampling_algorithm);
756
744
} else {
745
+ // Older versions might not have ExecuteSampleBlockBased implementation which runs block-based
746
+ // sampling stages separately. For both backward compatibility and simplicity, in this case we
747
+ // fallback to full table scan for ANALYZE. This only affects performance of colocated tables
748
+ // ANALYZE queries launched during upgrade process.
757
749
ysql_sampling_algorithm = YsqlSamplingAlgorithm::FULL_TABLE_SCAN;
758
750
}
759
751
760
- if (ysql_sampling_algorithm == YsqlSamplingAlgorithm::BLOCK_BASED_SAMPLING &&
761
- allow_separate_requests_for_sampling_stages) {
752
+ if (ysql_sampling_algorithm == YsqlSamplingAlgorithm::BLOCK_BASED_SAMPLING) {
762
753
sample_rows_picker_ = VERIFY_RESULT (TwoStageSampleRowsPicker::Make (
763
754
pg_session_, table_id, is_region_local, targrows, rand_state, read_time,
764
755
ysql_sampling_algorithm));
765
756
} else {
766
- // Old versions might not have ExecuteSampleBlockBased implementation which runs stages
767
- // separately. So for backward compatibility, if yb_allow_separate_requests_for_sampling_stages
768
- // is false, even for YsqlSamplingAlgorithm::BLOCK_BASED_SAMPLING we use SampleRowsPicker class
769
- // which expects tserver to run two-stages-in-single-run
770
- // DEPRECATED_ExecuteSampleBlockBasedColocated function.
771
- // New versions fall back to DEPRECATED_ExecuteSampleBlockBasedColocated when
772
- // PgsqlSamplingStatePB::is_blocks_sampling_stage is false and PgsqlReadRequestPB::sample_blocks
773
- // is empty.
774
757
sample_rows_picker_ = VERIFY_RESULT (SampleRowsPicker::Make (
775
758
pg_session_, table_id, is_region_local, targrows, rand_state, read_time,
776
759
ysql_sampling_algorithm));
0 commit comments