@@ -321,3 +321,119 @@ sql.plan.opt.order-by-nulls-non-standard
321321feature-usage
322322SELECT a FROM x ORDER BY b DESC NULLS LAST
323323----
324+
325+ # Test for clamped histogram selectivity.
326+
327+ feature-list
328+ sql.plan.clamped-histogram-selectivity
329+ sql.plan.clamped-inequality-selectivity
330+ ----
331+
332+ exec
333+ SET optimizer_clamp_low_histogram_selectivity = true;
334+ ----
335+
336+ exec
337+ SET optimizer_clamp_inequality_selectivity = true;
338+ ----
339+
340+ exec
341+ CREATE TYPE status_enum AS ENUM ('ACKNOWLEDGED', 'DROPPED', 'PENDING', 'SUCCEEDED');
342+ ----
343+
344+ exec
345+ CREATE TABLE t_large (
346+ k INT PRIMARY KEY,
347+ i INT,
348+ s STRING,
349+ e status_enum,
350+ INDEX (i),
351+ INDEX (s),
352+ INDEX (i) WHERE e = 'PENDING'
353+ )
354+ ----
355+
356+ exec
357+ ALTER TABLE t_large INJECT STATISTICS '[
358+ {
359+ "columns": ["k"],
360+ "created_at": "2018-01-01 1:00:00.00000+00:00",
361+ "row_count": 1000000000,
362+ "distinct_count": 1000000000,
363+ "null_count": 0,
364+ "avg_size": 2,
365+ "histo_col_type": "int",
366+ "histo_buckets": [
367+ {"num_eq": 0, "num_range": 0, "distinct_range": 0, "upper_bound": "0"},
368+ {"num_eq": 1, "num_range": 99000000, "distinct_range": 99000000, "upper_bound": "100000000"},
369+ {"num_eq": 1, "num_range": 199000000, "distinct_range": 199000000, "upper_bound": "300000000"},
370+ {"num_eq": 1, "num_range": 299000000, "distinct_range": 299000000, "upper_bound": "600000000"},
371+ {"num_eq": 1, "num_range": 399000000, "distinct_range": 399000000, "upper_bound": "1000000000"}
372+ ]
373+ },
374+ {
375+ "columns": ["i"],
376+ "created_at": "2018-01-01 1:00:00.00000+00:00",
377+ "row_count": 1000000000,
378+ "distinct_count": 44000000,
379+ "null_count": 0,
380+ "avg_size": 2,
381+ "histo_col_type": "int",
382+ "histo_buckets": [
383+ {"num_eq": 0, "num_range": 0, "distinct_range": 0, "upper_bound": "0"},
384+ {"num_eq": 10000000, "num_range": 90000000, "distinct_range": 10000000, "upper_bound": "100000000"},
385+ {"num_eq": 10000000, "num_range": 190000000, "distinct_range": 10000000, "upper_bound": "200000000"},
386+ {"num_eq": 20000000, "num_range": 280000000, "distinct_range": 10000000, "upper_bound": "300000000"},
387+ {"num_eq": 30000000, "num_range": 370000000, "distinct_range": 10000000, "upper_bound": "400000000"}
388+ ]
389+ },
390+ {
391+ "columns": ["s"],
392+ "created_at": "2018-01-01 1:00:00.00000+00:00",
393+ "row_count": 1000000000,
394+ "distinct_count": 400000000,
395+ "null_count": 0,
396+ "avg_size": 3,
397+ "histo_col_type": "string",
398+ "histo_buckets": [
399+ {"num_eq": 0, "num_range": 0, "distinct_range": 0, "upper_bound": "apple"},
400+ {"num_eq": 100000000, "num_range": 100000000, "distinct_range": 10000000, "upper_bound": "banana"},
401+ {"num_eq": 100000000, "num_range": 100000000, "distinct_range": 10000000, "upper_bound": "cherry"},
402+ {"num_eq": 200000000, "num_range": 100000000, "distinct_range": 10000000, "upper_bound": "mango"},
403+ {"num_eq": 200000000, "num_range": 100000000, "distinct_range": 10000000, "upper_bound": "pineapple"}
404+ ]
405+ },
406+ {
407+ "columns": ["e"],
408+ "created_at": "2018-01-01 1:00:00.00000+00:00",
409+ "row_count": 1000000000,
410+ "distinct_count": 4,
411+ "null_count": 0,
412+ "avg_size": 1,
413+ "histo_col_type": "status_enum",
414+ "histo_buckets": [
415+ {"num_eq": 1000000, "num_range": 0, "distinct_range": 0, "upper_bound": "ACKNOWLEDGED"},
416+ {"num_eq": 99000000, "num_range": 0, "distinct_range": 0, "upper_bound": "DROPPED"},
417+ {"num_eq": 900000000, "num_range": 0, "distinct_range": 0, "upper_bound": "SUCCEEDED"}
418+ ]
419+ }
420+ ]'
421+ ----
422+
423+ feature-usage
424+ SELECT * FROM t_large WHERE e = 'PENDING' AND k IN (110000000, 120000000, 130000000, 140000000)
425+ ----
426+ sql.plan.clamped-histogram-selectivity
427+
428+ feature-usage
429+ SELECT * FROM t_large WHERE k IN (100000000, 110000000, 120000000, 130000000) AND i > 500000000
430+ ----
431+ sql.plan.clamped-histogram-selectivity
432+ sql.plan.clamped-inequality-selectivity
433+
434+ # Cases where the selectivity clamps do not apply.
435+ feature-usage
436+ SELECT * FROM t_large WHERE e = 'SUCCEEDED';
437+ SELECT * FROM t_large;
438+ SELECT 1;
439+ ----
0 commit comments