| 907 | } |
| 908 | |
| 909 | bool deeplake_table_am_routine::scan_sample_next_tuple(TableScanDesc scan, |
| 910 | struct SampleScanState* scanstate, |
| 911 | TupleTableSlot* slot) |
| 912 | { |
| 913 | CHECK_FOR_INTERRUPTS(); |
| 914 | |
| 915 | DeeplakeScanData* scan_data = get_scan_data(scan); |
| 916 | if (!scan_data || !scan_data->sample_scan_active) { |
| 917 | return false; |
| 918 | } |
| 919 | |
| 920 | // Reset memory context to prevent unbounded growth |
| 921 | if (scan_data->scan_state.get_current_position() % num_tuples_to_reset_memory_context == 0) { |
| 922 | MemoryContextReset(scan_data->memory_context); |
| 923 | } |
| 924 | |
| 925 | // Switch to the dedicated memory context for this scan |
| 926 | pg::utils::memory_context_switcher context_switcher(scan_data->memory_context); |
| 927 | |
| 928 | constexpr double DEFAULT_SAMPLE_FRACTION = 0.1; // Default sample fraction |
| 929 | double sample_fraction = DEFAULT_SAMPLE_FRACTION; // default fallback |
| 930 | if (scan_data->current_sample_scanstate && scan_data->current_sample_scanstate->tsm_state) { |
| 931 | // If your TAM stores the fraction in tsm_state, cast and read it here |
| 932 | struct SampleState |
| 933 | { |
| 934 | double fraction; |
| 935 | }; |
| 936 | SampleState* sampler = static_cast<SampleState*>(scan_data->current_sample_scanstate->tsm_state); |
| 937 | sample_fraction = sampler->fraction; |
| 938 | } |
| 939 | |
| 940 | while (scan_data->scan_state.get_next_tuple(slot)) { |
| 941 | // random fraction, should come from scanstate->tsm_state |
| 942 | const double random_value = (double)random() / RAND_MAX; |
| 943 | |
| 944 | if (random_value <= sample_fraction) { |
| 945 | return true; |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | return false; |
| 950 | } |
| 951 | |
| 952 | IndexFetchTableData* deeplake_table_am_routine::begin_index_fetch(Relation rel) |
| 953 | { |
nothing calls this directly
no test coverage detected