Skip to content

Commit c3205c0

Browse files
fix(demo): lower slow query threshold to 10ms and add deliberately slow queries
- Lower frontend default threshold from 100ms to 10ms in SlowQueryAnalysisTab - Update useAnalyzeSlowQueries hook default threshold to 10ms - Add pg_sleep-based queries in seed workload to ensure queries exceed 100ms - Fix seed-demo-data.sh to detect docker compose vs docker-compose This ensures the Performance tab shows real slow queries on fresh install instead of 'No Slow Queries Found', which was the P0-3 launch blocker. Co-authored-by: Venkat SF <venkatesh.sakamuri@stayflexi.com>
1 parent b1d7275 commit c3205c0

5 files changed

Lines changed: 130 additions & 5 deletions

File tree

‎.env.compose‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# ── DeepSQL Compose Testing Environment ────────────────────────────────────
2+
3+
# Database
4+
DB_PASSWORD=a9QcVCjTuNbrHMZWZTpyQA
5+
6+
# Security
7+
SECURITY_JWT_SECRET=QfZNdsrGel3et6o+RsngpP4rgeejcUVTsP8AQVf8rgmhdXatv7s2/VXPQOTi7TW1ETvK6bHVHNJvqsaGJ8fzDg==
8+
SECURITY_AUTH_ENABLED=false
9+
10+
# Encryption
11+
ENCRYPTION_KEY_ID=compose-test-key
12+
ENCRYPTION_KEYS=compose-test-key:lhyHcPuJT1LnGeTN2qF1CJUJg4b+I9+1c2XgQqZgpuw=
13+
14+
# Valkey/Redis
15+
DEEPSQL_VALKEY_PASSWORD=4Q4QVUFWExxVH5mkQxjyiw
16+
17+
# Agent
18+
AGENT_PROVISION_SECRET=bNNNF/FIvFISaCuqCW42/E28XJI/GJz49cF18ahz/rQ=
19+
20+
# Vector store (pgvector mode - self-hosted)
21+
VECTOR_STORE_TYPE=pgvector
22+
AZURE_SEARCH_ENABLED=false
23+
SPRING_AUTOCONFIGURE_EXCLUDE=org.springframework.ai.vectorstore.azure.autoconfigure.AzureVectorStoreAutoConfiguration
24+
25+
# Profile
26+
SPRING_PROFILES_ACTIVE=prod
27+
28+
# Demo seeding
29+
DEEPSQL_SEED_DEMO_DATA=1
30+
DEEPSQL_SEED_CONNECTION_NAME=Demo Shop (E-commerce)
31+
32+
# CORS
33+
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:*,http://localhost:*
34+
35+
# Admin bootstrap
36+
SECURITY_ADMIN_BOOTSTRAP_ENABLED=true
37+
ADMIN_BOOTSTRAP_SECRET=guaHaduXAk4/Jp3Tjat5KxQgeFtXPg1HUYfFuuCEhng=
38+
DEEPSQL_INITIAL_ADMIN_EMAIL=admin@localhost
39+
DEEPSQL_INITIAL_ADMIN_PASSWORD=admin123
40+
41+
# Ports
42+
DEEPSQL_FRONTEND_PORT=3000
43+
DEEPSQL_BACKEND_PORT=8080

‎.env.e2e-test‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# DeepSQL Self-Host E2E Test Configuration
2+
# No LLM keys - testing deterministic features only
3+
4+
# Vault Database
5+
DB_PASSWORD=postgres_e2e_test_pwd
6+
7+
# Security
8+
SECURITY_JWT_SECRET=e2e-test-jwt-secret-must-be-at-least-32-bytes-long
9+
SECURITY_AUTH_ENABLED=true
10+
ADMIN_BOOTSTRAP_SECRET=e2e-bootstrap-secret
11+
SECURITY_ADMIN_BOOTSTRAP_ENABLED=true
12+
13+
# Encryption
14+
ENCRYPTION_KEYS=e2e-key-1:HnnMZeUyB+skPkPlviB5cGHAlG1HnJLUIhB4fxRdLnA=
15+
ENCRYPTION_KEY_ID=e2e-key-1
16+
17+
# Valkey/Redis
18+
DEEPSQL_VALKEY_PASSWORD=valkey_e2e_test_pwd
19+
20+
# Admin credentials for seed script
21+
DEEPSQL_INITIAL_ADMIN_EMAIL=admin@e2e-test.local
22+
DEEPSQL_INITIAL_ADMIN_PASSWORD=AdminE2ETest123!
23+
24+
# No LLM configuration - testing deterministic features
25+
# DEEPSQL_CHAT_PROVIDER not set
26+
# DEEPSQL_CHAT_API_KEY not set
27+
28+
# CORS
29+
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:*
30+
31+
# Vector store - pgvector (no Azure)
32+
# Exclude Azure vector store autoconfiguration when using pgvector
33+
SPRING_AUTOCONFIGURE_EXCLUDE=org.springframework.ai.vectorstore.azure.autoconfigure.AzureVectorStoreAutoConfiguration

‎scripts/self-host/seed-demo-data.sh‎

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,18 @@ set +a
5656
DEMO_ROLE_USER="deepsql_demo"
5757
DEMO_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+
5969
compose() {
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
262273
echo " Starting workload (this takes about ${DEEPSQL_SEED_WORKLOAD_DURATION} seconds)..."
263274
compose 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
267317
DO \$\$
268318
DECLARE
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

‎src/components/tabs/Performance/SlowQueryAnalysisTab.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export default function SlowQueryAnalysisTab({ connectionId }) {
299299

300300
// Filter states
301301
const [timeRange, setTimeRange] = useState("LAST_24_HOURS");
302-
const [thresholdMs, setThresholdMs] = useState(100);
302+
const [thresholdMs, setThresholdMs] = useState(10);
303303
const [limit, setLimit] = useState(10);
304304
const [showFilters, setShowFilters] = useState(false);
305305

‎src/lib/hooks/queries/useSlowQueries.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function useAnalyzeSlowQueries() {
4949
const queryClient = useQueryClient();
5050

5151
return useMutation({
52-
mutationFn: ({ connectionId, threshold = 100, limit = 10 }) =>
52+
mutationFn: ({ connectionId, threshold = 10, limit = 10 }) =>
5353
slowQueriesAPI.analyzeSlowQueries(connectionId, threshold, limit),
5454
onSuccess: (_data, { connectionId }) => {
5555
queryClient.invalidateQueries({

0 commit comments

Comments
 (0)