#!/bin/sh set -eu repo=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) output=$(mktemp) cleanup() { rm -f "$output"; } trap cleanup EXIT INT TERM docker compose exec -T db psql -X -U rf4 -d rf4_spotter \ < "$repo/deploy/tackle-query-plan-gate.sql" > "$output" for plan in tackle_catalog_filter tackle_combinations; do grep -F "PLAN $plan" "$output" >/dev/null done awk ' /Execution Time:/ { count += 1; if (($3 + 0) > 250) { print "Tackle query plan exceeded 250 ms: " $0 > "/dev/stderr"; failed = 1 } } END { if (count != 2 || failed) exit 1 } ' "$output" grep -A40 'PLAN tackle_catalog_filter' "$output" | grep -Eq 'Index Scan|Index Only Scan|Bitmap Index Scan' grep -A60 'PLAN tackle_combinations' "$output" | grep -Eq 'Index Scan|Bitmap Index Scan' grep 'Execution Time:' "$output" echo "Tackle query-plan gate passed: indexed catalog and combination paths under 250 ms"