@@ -56,8 +56,18 @@ set +a
5656DEMO_ROLE_USER=" deepsql_demo"
5757DEMO_ROLE_PASSWORD=" deepsql_demo_password"
5858
59+ # Detect docker compose command (v2 plugin vs standalone)
60+ if docker compose version & > /dev/null; then
61+ DOCKER_COMPOSE_CMD=" docker compose"
62+ elif command -v docker-compose & > /dev/null; then
63+ DOCKER_COMPOSE_CMD=" docker-compose"
64+ else
65+ echo " Error: Neither 'docker compose' nor 'docker-compose' found." >&2
66+ exit 1
67+ fi
68+
5969compose () {
60- DEEPSQL_RUNTIME_ENV_FILE=" $ENV_FILE " docker compose \
70+ DEEPSQL_RUNTIME_ENV_FILE=" $ENV_FILE " $DOCKER_COMPOSE_CMD \
6171 --project-name " $PROJECT_NAME " \
6272 --env-file " $ENV_FILE " \
6373 -f " $COMPOSE_FILE " \
@@ -259,11 +269,51 @@ compose exec -T postgres psql -U postgres -d demo_shop -c "SELECT pg_stat_statem
259269
260270# Run inefficient queries that will be captured by pg_stat_statements
261271# These patterns are intentionally suboptimal to trigger recommendations
272+ # Some queries use pg_sleep to ensure they exceed 100ms threshold
262273echo " Starting workload (this takes about ${DEEPSQL_SEED_WORKLOAD_DURATION} seconds)..."
263274compose exec -T postgres psql -U postgres -d demo_shop -v ON_ERROR_STOP=1 << EOWORK
264275-- Workload simulation for pg_stat_statements
265276-- Each pattern runs multiple times to accumulate meaningful statistics
266-
277+ -- Deliberately slow queries (>100ms) are marked with pg_sleep
278+
279+ -- First: Run deliberately slow queries that will DEFINITELY show up at 100ms threshold
280+ -- These queries simulate "stuck" or poorly optimized production queries
281+
282+ -- Slow Query 1: Full table scan with sleep (simulates missing index)
283+ -- This query would benefit from an index on audit_log(table_name, changed_at)
284+ SELECT COUNT(*), pg_sleep(0.15)
285+ FROM audit_log
286+ WHERE table_name = 'orders'
287+ AND changed_at > NOW() - INTERVAL '7 days';
288+
289+ -- Run it multiple times to accumulate calls
290+ SELECT COUNT(*), pg_sleep(0.12)
291+ FROM audit_log
292+ WHERE table_name = 'orders'
293+ AND changed_at > NOW() - INTERVAL '7 days';
294+
295+ SELECT COUNT(*), pg_sleep(0.11)
296+ FROM audit_log
297+ WHERE table_name = 'orders'
298+ AND changed_at > NOW() - INTERVAL '7 days';
299+
300+ -- Slow Query 2: Cross-join style lookup with LOWER() function (prevents index use)
301+ -- This query would benefit from a functional index on LOWER(status)
302+ SELECT COUNT(*), pg_sleep(0.14)
303+ FROM orders
304+ WHERE LOWER(status) = 'delivered' AND total_amount > 100;
305+
306+ SELECT COUNT(*), pg_sleep(0.13)
307+ FROM orders
308+ WHERE LOWER(status) = 'delivered' AND total_amount > 100;
309+
310+ -- Slow Query 3: Missing composite index on frequently filtered columns
311+ SELECT COUNT(*), pg_sleep(0.12)
312+ FROM orders o
313+ JOIN customers c ON o.customer_id = c.id
314+ WHERE o.status = 'pending' AND o.payment_status = 'paid';
315+
316+ -- Now run the loop for additional patterns at faster speeds
267317DO \$\$
268318DECLARE
269319 i int;
@@ -275,7 +325,6 @@ BEGIN
275325
276326 WHILE (EXTRACT(EPOCH FROM (clock_timestamp() - start_time)) < duration_seconds) LOOP
277327 -- Pattern 1: LOWER() on indexed column (prevents index use)
278- -- This is a common anti-pattern that should trigger a recommendation
279328 SELECT COUNT(*) INTO result_count FROM orders
280329 WHERE LOWER(status) = 'delivered' AND total_amount > 100;
281330
0 commit comments