|
| 1 | +exec-ddl |
| 2 | +CREATE TABLE sel (a INT PRIMARY KEY) WITH (canary_window = '30s') |
| 3 | +---- |
| 4 | + |
| 5 | +# Single stats case: both canary and stable path should use the same stats. |
| 6 | +exec-ddl |
| 7 | +ALTER TABLE sel INJECT STATISTICS '[ |
| 8 | + { |
| 9 | + "columns": ["a"], |
| 10 | + "created_at": "2018-01-01 11:00:00.00000+00:00", |
| 11 | + "row_count": 20, |
| 12 | + "distinct_count": 20 |
| 13 | + } |
| 14 | + ]' |
| 15 | +---- |
| 16 | + |
| 17 | +opt stats-as-of=(2018-01-01 11:00:10.00000+00:00) canary-fraction=1.0 |
| 18 | +SELECT a FROM sel ORDER BY a |
| 19 | +---- |
| 20 | +scan sel |
| 21 | + ├── columns: a:1(int!null) |
| 22 | + ├── stats: [rows=20] |
| 23 | + ├── key: (1) |
| 24 | + └── ordering: +1 |
| 25 | + |
| 26 | +opt stats-as-of=(2018-01-01 11:00:10.00000+00:00) canary-fraction=0.0 |
| 27 | +SELECT a FROM sel ORDER BY a |
| 28 | +---- |
| 29 | +scan sel |
| 30 | + ├── columns: a:1(int!null) |
| 31 | + ├── stats: [rows=20] |
| 32 | + ├── key: (1) |
| 33 | + └── ordering: +1 |
| 34 | + |
| 35 | + |
| 36 | +# More than 2 stats available: should only consider the latest 2 stats as possible candidates. |
| 37 | +exec-ddl |
| 38 | +ALTER TABLE sel INJECT STATISTICS '[ |
| 39 | + { |
| 40 | + "columns": ["a"], |
| 41 | + "created_at": "2018-01-01 11:00:40.00000+00:00", |
| 42 | + "row_count": 30, |
| 43 | + "distinct_count": 30 |
| 44 | + }, |
| 45 | + { |
| 46 | + "columns": ["a"], |
| 47 | + "created_at": "2018-01-01 11:00:00.00000+00:00", |
| 48 | + "row_count": 20, |
| 49 | + "distinct_count": 20 |
| 50 | + }, |
| 51 | + { |
| 52 | + "columns": ["a"], |
| 53 | + "created_at": "2018-01-01 10:59:40.00000+00:00", |
| 54 | + "row_count": 10, |
| 55 | + "distinct_count": 10 |
| 56 | + } |
| 57 | + ]' |
| 58 | +---- |
| 59 | + |
| 60 | +opt stats-as-of=(2018-01-01 11:00:50.00000+00:00) canary-fraction=1.0 |
| 61 | +SELECT a FROM sel ORDER BY a |
| 62 | +---- |
| 63 | +scan sel |
| 64 | + ├── columns: a:1(int!null) |
| 65 | + ├── stats: [rows=30] |
| 66 | + ├── key: (1) |
| 67 | + └── ordering: +1 |
| 68 | + |
| 69 | +opt stats-as-of=(2018-01-01 11:00:50.00000+00:00) canary-fraction=0.0 |
| 70 | +SELECT a FROM sel ORDER BY a |
| 71 | +---- |
| 72 | +scan sel |
| 73 | + ├── columns: a:1(int!null) |
| 74 | + ├── stats: [rows=20] |
| 75 | + ├── key: (1) |
| 76 | + └── ordering: +1 |
| 77 | + |
| 78 | +# Optimize as of a later timestamp, so that latest stats is out of the |
| 79 | +# canary window, and canary stats has been promoted to stable stats. |
| 80 | +opt stats-as-of=(2018-01-01 11:01:30.00000+00:00) canary-fraction=1.0 |
| 81 | +SELECT a FROM sel ORDER BY a |
| 82 | +---- |
| 83 | +scan sel |
| 84 | + ├── columns: a:1(int!null) |
| 85 | + ├── stats: [rows=30] |
| 86 | + ├── key: (1) |
| 87 | + └── ordering: +1 |
| 88 | + |
| 89 | +opt stats-as-of=(2018-01-01 11:01:30.00000+00:00) canary-fraction=0.0 |
| 90 | +SELECT a FROM sel ORDER BY a |
| 91 | +---- |
| 92 | +scan sel |
| 93 | + ├── columns: a:1(int!null) |
| 94 | + ├── stats: [rows=30] |
| 95 | + ├── key: (1) |
| 96 | + └── ordering: +1 |
| 97 | + |
| 98 | +# Test time traveling of stats_as_of. |
| 99 | +opt stats-as-of=(2018-01-01 11:00:20.00000+00:00) canary-fraction=1.0 |
| 100 | +SELECT a FROM sel ORDER BY a |
| 101 | +---- |
| 102 | +scan sel |
| 103 | + ├── columns: a:1(int!null) |
| 104 | + ├── stats: [rows=20] |
| 105 | + ├── key: (1) |
| 106 | + └── ordering: +1 |
| 107 | + |
| 108 | +opt stats-as-of=(2018-01-01 11:00:20.00000+00:00) canary-fraction=0.0 |
| 109 | +SELECT a FROM sel ORDER BY a |
| 110 | +---- |
| 111 | +scan sel |
| 112 | + ├── columns: a:1(int!null) |
| 113 | + ├── stats: [rows=10] |
| 114 | + ├── key: (1) |
| 115 | + └── ordering: +1 |
| 116 | + |
| 117 | +# If travelling way too back in the past so that no stats are valid, |
| 118 | +# both paths should use the fake stats (with rows = 1000). |
| 119 | +opt stats-as-of=(2018-01-01 10:00:00.00000+00:00) canary-fraction=1.0 |
| 120 | +SELECT a FROM sel ORDER BY a |
| 121 | +---- |
| 122 | +scan sel |
| 123 | + ├── columns: a:1(int!null) |
| 124 | + ├── stats: [rows=1000] |
| 125 | + ├── key: (1) |
| 126 | + └── ordering: +1 |
| 127 | + |
| 128 | +opt stats-as-of=(2018-01-01 10:00:00.00000+00:00) canary-fraction=0.0 |
| 129 | +SELECT a FROM sel ORDER BY a |
| 130 | +---- |
| 131 | +scan sel |
| 132 | + ├── columns: a:1(int!null) |
| 133 | + ├── stats: [rows=1000] |
| 134 | + ├── key: (1) |
| 135 | + └── ordering: +1 |
0 commit comments