|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# This oracle runs the reproducer script with the psql variable :hyper set |
| 4 | +# to false and true, and compares the output. The script passes the variable |
| 5 | +# into CREATE TABLE ... WITH (tsdb.hypertable = :hyper, ...), so the same |
| 6 | +# statements run against a plain Postgres table and a TimescaleDB |
| 7 | +# hypertable. The admissible bug must lead to a change in script output |
| 8 | +# between the two. |
| 9 | +# |
| 10 | +# An admissible repro script: |
| 11 | +# |
| 12 | +# Must be runnable on same database multiple times in sequence. |
| 13 | +# |
| 14 | +# Must run exactly the same statements no matter if it runs against the |
| 15 | +# plain table or the hypertable. |
| 16 | +# |
| 17 | +# |
| 18 | +# Must not use the psql meta-commands. |
| 19 | +# |
| 20 | +# Must not require superuser privileges. |
| 21 | +# |
| 22 | +# The output of an admissible repro script: |
| 23 | +# |
| 24 | +# Must be sufficiently ordered to prevent false positives (i.e. ORDER BY, no |
| 25 | +# ties). |
| 26 | +# |
| 27 | +# Must not depend on floating point precision or numeric stability. |
| 28 | +# |
| 29 | +# Must be independent from arbitrary environmental influence like the OID values |
| 30 | +# or chunk identifiers. |
| 31 | +# |
| 32 | +# Must not change when the script runs on the same database multiple times in |
| 33 | +# sequence. |
| 34 | +set -eu |
| 35 | + |
| 36 | +psql <<<'alter database :"DBNAME" set client_min_messages to error' |
| 37 | + |
| 38 | +if ! psql -v hyper=false -f "$1" > result_plain.txt |
| 39 | +then |
| 40 | + echo "Repro errors out, not admissible" |
| 41 | + exit 0 |
| 42 | +fi |
| 43 | + |
| 44 | +if psql -v hyper=maybe -f "$1" &> result_probe.txt |
| 45 | +then |
| 46 | + echo "Repro does not use :hyper for tsdb.hypertable, not admissible" |
| 47 | + exit 0 |
| 48 | +fi |
| 49 | + |
| 50 | +if ! psql -v hyper=off -f "$1" > result_plain_synonym.txt |
| 51 | +then |
| 52 | + echo "Repro errors out, not admissible" |
| 53 | + exit 0 |
| 54 | +fi |
| 55 | + |
| 56 | + |
| 57 | +if ! psql -v hyper=true -f "$1" > result_hyper.txt |
| 58 | +then |
| 59 | + echo "Repro errors out, not admissible" |
| 60 | + exit 0 |
| 61 | +fi |
| 62 | + |
| 63 | +if ! psql -v hyper=true -c "set enable_seqscan to off;" -f "$1" > result_hyper_noseq.txt |
| 64 | +then |
| 65 | + echo "Repro errors out, not admissible" |
| 66 | + exit 0 |
| 67 | +fi |
| 68 | + |
| 69 | +if ! psql -v hyper=true -c "set enable_indexscan to off;" -f "$1" > result_hyper_noindex.txt |
| 70 | +then |
| 71 | + echo "Repro errors out, not admissible" |
| 72 | + exit 0 |
| 73 | +fi |
| 74 | + |
| 75 | +if ! psql -v hyper=true -c "set enable_hashagg to off;" -f "$1" > result_hyper_nohashagg.txt |
| 76 | +then |
| 77 | + echo "Repro errors out, not admissible" |
| 78 | + exit 0 |
| 79 | +fi |
| 80 | + |
| 81 | +if ! psql -v hyper=true -c " |
| 82 | + set max_parallel_workers_per_gather = 8; |
| 83 | + set parallel_setup_cost = 0; |
| 84 | + set parallel_tuple_cost = 0; |
| 85 | + set min_parallel_table_scan_size = 0; |
| 86 | + set min_parallel_index_scan_size = 0; |
| 87 | + " -f "$1" > result_hyper_para.txt |
| 88 | +then |
| 89 | + echo "Repro errors out, not admissible" |
| 90 | + exit 0 |
| 91 | +fi |
| 92 | + |
| 93 | +if ! psql -v hyper=true -c "set work_mem = '4GB'" -f "$1" > result_hyper_mem.txt |
| 94 | +then |
| 95 | + echo "Repro errors out, not admissible" |
| 96 | + exit 0 |
| 97 | +fi |
| 98 | + |
| 99 | +if ! psql -v hyper=true -c " |
| 100 | + set enable_hashagg to off; |
| 101 | + set enable_sort to off; |
| 102 | + set timescaledb.enable_chunkwise_aggregation to off; |
| 103 | + " -f "$1" > result_hyper_rowsort.txt 2> result_hyper_rowsort.err |
| 104 | +then |
| 105 | + echo "Repro errors out, not admissible" |
| 106 | + exit 0 |
| 107 | +fi |
| 108 | + |
| 109 | +if ! diff -u result_plain.txt result_plain_synonym.txt \ |
| 110 | + || ! diff -u result_hyper.txt result_hyper_noseq.txt \ |
| 111 | + || ! diff -u result_hyper.txt result_hyper_noindex.txt \ |
| 112 | + || ! diff -u result_hyper.txt result_hyper_nohashagg.txt \ |
| 113 | + || ! diff -u result_hyper.txt result_hyper_para.txt \ |
| 114 | + || ! diff -u result_hyper.txt result_hyper_mem.txt \ |
| 115 | + || ! diff -u result_hyper.txt result_hyper_rowsort.txt |
| 116 | +then |
| 117 | + echo "Repro gives different results between runs, not admissible" |
| 118 | + exit 0 |
| 119 | +fi |
| 120 | + |
| 121 | +echo |
| 122 | +echo '```diff' |
| 123 | +echo |
| 124 | + |
| 125 | +if diff -u result_plain.txt result_hyper.txt |
| 126 | +then |
| 127 | + result=0 |
| 128 | +else |
| 129 | + result=$? |
| 130 | +fi |
| 131 | + |
| 132 | +echo |
| 133 | +echo '```' |
| 134 | +echo |
| 135 | + |
| 136 | +if [ "${result}" -eq 0 ] |
| 137 | +then |
| 138 | + echo "Same result with hypertable false/true, error not reproduced" |
| 139 | + exit 0 |
| 140 | +fi |
| 141 | + |
| 142 | +echo "Reproduced" |
| 143 | +exit 1 |
0 commit comments