1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2026 Nowledge
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Compile-time cardinality heuristics used when stronger statistics are absent.
//!
//! These preserve the existing estimates; they are not benchmark-calibrated
//! probabilities or a public tuning API. Equal values with different meanings
//! stay separate so that later calibration is an explicit, reviewable decision.
//! Callers retain their statistics precedence, ceiling division, saturation,
//! NDV caps and minimum-one estimates. Arithmetic identities are not defaults.
/// Unknown predicate shape or binding: retain half of the input rows.
pub const FILTER_SELECTIVITY_DIVISOR: u64 = 2;
/// Unsupported grouping expression or missing key NDV: estimate one group per
/// four input rows. Known grouping keys instead use their capped NDV product.
pub const AGGREGATE_GROUPS_DIVISOR: u64 = 4;
/// String predicates lack query-specific statistics. These denominators are
/// capped by the property's NDV, for both nodes and relationships.
pub const CONTAINS_SELECTIVITY_DIVISOR: u64 = 4;
pub const STARTS_WITH_SELECTIVITY_DIVISOR: u64 = 8;
pub const ENDS_WITH_SELECTIVITY_DIVISOR: u64 = 6;
/// Without a null-frequency statistic, estimate rows / min(max(NDV, 1), 10).
/// IS NOT NULL uses the complementary row count with its existing floor.
pub const NULL_SELECTIVITY_DIVISOR_CAP: u64 = 10;
/// Missing or empty range histogram: retain half of the input population.
pub const RANGE_SELECTIVITY_DIVISOR: u64 = 2;
/// A sampled histogram uses an add-one prior: one matching pseudo-observation
/// out of two total. Complete histograms do not use this prior.
pub const SAMPLED_HISTOGRAM_MATCH_PSEUDOCOUNT: u64 = 1;
pub const SAMPLED_HISTOGRAM_TOTAL_PSEUDOCOUNT: u64 = 2;
/// Until query-specific full-text statistics exist, retain a quarter of the
/// label's rows, before and after projection fusion. Materialization does not
/// change selectivity, and an already-covered predicate is not applied twice.
pub const FULL_TEXT_SELECTIVITY_DIVISOR: u64 = 4;