Skip to content

Commit 591e697

Browse files
committed
test: add bigger slow query log reading test
Signed-off-by: Andres Taylor <[email protected]>
1 parent bc0e08a commit 591e697

File tree

4 files changed

+568
-2
lines changed

4 files changed

+568
-2
lines changed
+219
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
/bin/mysqld, Version: 8.0.26 (Source distribution). started with:
2+
Tcp port: 3306 Unix socket: /tmp/mysql.sock
3+
Time Id Command Argument
4+
# Time: 2023-08-01T12:00:01.000123Z
5+
# User@Host: user1[user1] @ [192.168.1.101] Id: 800001
6+
# Query_time: 0.150623 Lock_time: 0.002000 Rows_sent: 5 Rows_examined: 2000
7+
use testdb;
8+
SET timestamp=1690891201;
9+
SELECT p.name, AVG(r.rating) as avg_rating FROM products p JOIN reviews r ON p.id = r.product_id GROUP BY p.id ORDER BY avg_rating DESC LIMIT 5;
10+
# Time: 2023-08-01T12:00:02.000456Z
11+
# User@Host: admin[admin] @ localhost [] Id: 800002
12+
# Query_time: 0.200012 Lock_time: 0.003000 Rows_sent: 10 Rows_examined: 5000
13+
SET timestamp=1690891202;
14+
SELECT u.username, SUM(o.total_amount) as total_spent FROM users u JOIN orders o ON u.id = o.user_id WHERE o.created_at BETWEEN '2023-07-01' AND '2023-07-31' GROUP BY u.id HAVING total_spent > 500;
15+
# Time: 2023-08-01T12:00:03.000789Z
16+
# User@Host: user2[user2] @ [192.168.1.102] Id: 800003
17+
# Query_time: 0.180234 Lock_time: 0.001500 Rows_sent: 20 Rows_examined: 10000
18+
SET timestamp=1690891203;
19+
SELECT c.name, COUNT(o.id) as order_count
20+
FROM categories c
21+
JOIN products p ON c.id = p.category_id
22+
JOIN order_items oi ON p.id = oi.product_id
23+
JOIN orders o ON oi.order_id = o.id
24+
GROUP BY c.id;
25+
# Time: 2023-08-01T12:00:04.001012Z
26+
# User@Host: user3[user3] @ [192.168.1.103] Id: 800004
27+
# Query_time: 0.130456 Lock_time: 0.002300 Rows_sent: 15 Rows_examined: 8000
28+
SET timestamp=1690891204;
29+
SELECT p.name, i.stock_level
30+
FROM products p
31+
JOIN inventory i ON p.id = i.product_id
32+
WHERE i.stock_level < 5;
33+
# Time: 2023-08-01T12:00:05.001345Z
34+
# User@Host: user4[user4] @ [192.168.1.104] Id: 800005
35+
# Query_time: 0.210678 Lock_time: 0.004000 Rows_sent: 25 Rows_examined: 15000
36+
SET timestamp=1690891205;
37+
SELECT c.name, SUM(oi.price * oi.quantity) as total_sales
38+
FROM categories c
39+
JOIN products p ON c.id = p.category_id
40+
JOIN order_items oi ON p.id = oi.product_id
41+
GROUP BY c.id
42+
ORDER BY total_sales DESC
43+
LIMIT 3;
44+
# Time: 2023-08-01T12:00:06.001678Z
45+
# User@Host: user5[user5] @ [192.168.1.105] Id: 800006
46+
# Query_time: 0.140789 Lock_time: 0.001800 Rows_sent: 1 Rows_examined: 4000
47+
SET timestamp=1690891206;
48+
SELECT o.id, o.created_at
49+
FROM orders o
50+
LEFT JOIN shipments s ON o.id = s.order_id
51+
WHERE s.shipped_date IS NULL AND o.created_at < DATE_SUB(NOW(), INTERVAL 7 DAY);
52+
# Time: 2023-08-01T12:00:07.002001Z
53+
# User@Host: user1[user1] @ [192.168.1.101] Id: 800001
54+
# Query_time: 0.160123 Lock_time: 0.002100 Rows_sent: 3 Rows_examined: 2500
55+
SET timestamp=1690891207;
56+
SELECT p.payment_method, AVG(o.total_amount) as avg_order_value
57+
FROM payments p
58+
JOIN orders o ON p.order_id = o.id
59+
GROUP BY p.payment_method;
60+
# Time: 2023-08-01T12:00:08.002334Z
61+
# User@Host: user2[user2] @ [192.168.1.102] Id: 800003
62+
# Query_time: 0.190456 Lock_time: 0.001600 Rows_sent: 50 Rows_examined: 12000
63+
SET timestamp=1690891208;
64+
SELECT DATE(o.created_at) as order_date, COUNT(*) as order_count
65+
FROM orders o
66+
WHERE o.created_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)
67+
GROUP BY DATE(o.created_at);
68+
# Time: 2023-08-01T12:00:09.002667Z
69+
# User@Host: user3[user3] @ [192.168.1.103] Id: 800004
70+
# Query_time: 0.220789 Lock_time: 0.003300 Rows_sent: 30 Rows_examined: 18000
71+
SET timestamp=1690891209;
72+
SELECT m.sender_id, COUNT(DISTINCT m.receiver_id) as unique_receivers
73+
FROM messages m
74+
GROUP BY m.sender_id
75+
HAVING unique_receivers > 10;
76+
# Time: 2023-08-01T12:00:10.003000Z
77+
# User@Host: user4[user4] @ [192.168.1.104] Id: 800005
78+
# Query_time: 0.250012 Lock_time: 0.005000 Rows_sent: 2 Rows_examined: 6000
79+
SET timestamp=1690891210;
80+
SELECT u.id, u.username
81+
FROM users u
82+
LEFT JOIN orders o ON u.id = o.user_id
83+
WHERE o.id IS NULL;
84+
# Time: 2023-08-01T12:00:11.003333Z
85+
# User@Host: user5[user5] @ [192.168.1.105] Id: 800006
86+
# Query_time: 0.170345 Lock_time: 0.001700 Rows_sent: 100 Rows_examined: 5000
87+
SET timestamp=1690891211;
88+
SELECT u.username, SUM(o.total_amount) as total_spent
89+
FROM users u
90+
JOIN orders o ON u.id = o.user_id
91+
WHERE o.created_at BETWEEN '2023-06-01' AND '2023-06-30'
92+
GROUP BY u.id
93+
HAVING total_spent > 2000;
94+
# Time: 2023-08-01T12:00:12.003666Z
95+
# User@Host: user1[user1] @ [192.168.1.101] Id: 800001
96+
# Query_time: 0.210456 Lock_time: 0.002500 Rows_sent: 7 Rows_examined: 3000
97+
SET timestamp=1690891212;
98+
SELECT p.name, AVG(r.rating) as avg_rating
99+
FROM products p
100+
JOIN reviews r ON p.id = r.product_id
101+
GROUP BY p.id
102+
ORDER BY avg_rating DESC
103+
LIMIT 10;
104+
# Time: 2023-08-01T12:00:13.003999Z
105+
# User@Host: user2[user2] @ [192.168.1.102] Id: 800003
106+
# Query_time: 0.180789 Lock_time: 0.002200 Rows_sent: 12 Rows_examined: 7000
107+
SET timestamp=1690891213;
108+
SELECT p.name, i.stock_level
109+
FROM products p
110+
JOIN inventory i ON p.id = i.product_id
111+
WHERE i.stock_level < 15;
112+
# Time: 2023-08-01T12:00:14.004332Z
113+
# User@Host: user3[user3] @ [192.168.1.103] Id: 800004
114+
# Query_time: 0.200123 Lock_time: 0.001900 Rows_sent: 1 Rows_examined: 4500
115+
SET timestamp=1690891214;
116+
SELECT o.id, o.created_at
117+
FROM orders o
118+
LEFT JOIN shipments s ON o.id = s.order_id
119+
WHERE s.shipped_date IS NULL AND o.created_at < DATE_SUB(NOW(), INTERVAL 14 DAY);
120+
# Time: 2023-08-01T12:00:15.004665Z
121+
# User@Host: user4[user4] @ [192.168.1.104] Id: 800005
122+
# Query_time: 0.240456 Lock_time: 0.003500 Rows_sent: 5 Rows_examined: 10000
123+
SET timestamp=1690891215;
124+
SELECT u.id, u.username
125+
FROM users u
126+
LEFT JOIN orders o ON u.id = o.user_id
127+
WHERE o.id IS NULL;
128+
# Time: 2023-08-01T12:00:16.004998Z
129+
# User@Host: user5[user5] @ [192.168.1.105] Id: 800006
130+
# Query_time: 0.190789 Lock_time: 0.002600 Rows_sent: 8 Rows_examined: 6000
131+
SET timestamp=1690891216;
132+
SELECT c.name, COUNT(o.id) as order_count
133+
FROM categories c
134+
JOIN products p ON c.id = p.category_id
135+
JOIN order_items oi ON p.id = oi.product_id
136+
JOIN orders o ON oi.order_id = o.id
137+
GROUP BY c.id;
138+
# Time: 2023-08-01T12:00:17.005331Z
139+
# User@Host: user1[user1] @ [192.168.1.101] Id: 800001
140+
# Query_time: 0.170123 Lock_time: 0.001800 Rows_sent: 4 Rows_examined: 3500
141+
SET timestamp=1690891217;
142+
SELECT p.payment_method, AVG(o.total_amount) as avg_order_value
143+
FROM payments p
144+
JOIN orders o ON p.order_id = o.id
145+
GROUP BY p.payment_method;
146+
# Time: 2023-08-01T12:00:18.005664Z
147+
# User@Host: user2[user2] @ [192.168.1.102] Id: 800003
148+
# Query_time: 0.160456 Lock_time: 0.001400 Rows_sent: 6 Rows_examined: 3000
149+
SET timestamp=1690891218;
150+
SELECT m.sender_id, COUNT(DISTINCT m.receiver_id) as unique_receivers
151+
FROM messages m
152+
GROUP BY m.sender_id
153+
HAVING unique_receivers > 5;
154+
# Time: 2023-08-01T12:00:19.005997Z
155+
# User@Host: user3[user3] @ [192.168.1.103] Id: 800004
156+
# Query_time: 0.210789 Lock_time: 0.003000 Rows_sent: 9 Rows_examined: 7000
157+
SET timestamp=1690891219;
158+
SELECT u.username, SUM(o.total_amount) as total_spent
159+
FROM users u
160+
JOIN orders o ON u.id = o.user_id
161+
WHERE o.created_at BETWEEN '2023-07-01' AND '2023-07-31'
162+
GROUP BY u.id
163+
HAVING total_spent > 1500;
164+
# Time: 2023-08-01T12:00:20.006330Z
165+
# User@Host: user4[user4] @ [192.168.1.104] Id: 800005
166+
# Query_time: 0.180456 Lock_time: 0.002300 Rows_sent: 3 Rows_examined: 4000
167+
SET timestamp=1690891220;
168+
SELECT DATE(o.created_at) as order_date, COUNT(*) as order_count
169+
FROM orders o
170+
WHERE o.created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)
171+
GROUP BY DATE(o.created_at);
172+
# Time: 2023-08-01T12:00:21.006663Z
173+
# User@Host: user5[user5] @ [192.168.1.105] Id: 800006
174+
# Query_time: 0.220123 Lock_time: 0.003800 Rows_sent: 2 Rows_examined: 8000
175+
SET timestamp=1690891221;
176+
SELECT u.id, u.username
177+
FROM users u
178+
JOIN orders o ON u.id = o.user_id
179+
JOIN reviews r ON u.id = r.user_id
180+
WHERE o.created_at >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
181+
AND r.created_at >= DATE_SUB(NOW(), INTERVAL 1 MONTH);
182+
# Time: 2023-08-01T12:00:22.006996Z
183+
# User@Host: user1[user1] @ [192.168.1.101] Id: 800001
184+
# Query_time: 0.190789 Lock_time: 0.002100 Rows_sent: 6 Rows_examined: 5000
185+
SET timestamp=1690891222;
186+
SELECT c.name, SUM(oi.price * oi.quantity) as total_sales
187+
FROM categories c
188+
JOIN products p ON c.id = p.category_id
189+
JOIN order_items oi ON p.id = oi.product_id
190+
GROUP BY c.id
191+
ORDER BY total_sales DESC
192+
LIMIT 5;
193+
# Time: 2023-08-01T12:00:23.007329Z
194+
# User@Host: user2[user2] @ [192.168.1.102] Id: 800003
195+
# Query_time: 0.160456 Lock_time: 0.001500 Rows_sent: 10 Rows_examined: 3500
196+
SET timestamp=1690891223;
197+
SELECT p.name, AVG(r.rating) as avg_rating
198+
FROM products p
199+
JOIN reviews r ON p.id = r.product_id
200+
WHERE r.created_at >= DATE_SUB(NOW(), INTERVAL 1 WEEK)
201+
GROUP BY p.id
202+
ORDER BY avg_rating DESC
203+
LIMIT 5;
204+
# Time: 2023-08-01T12:00:24.007662Z
205+
# User@Host: user3[user3] @ [192.168.1.103] Id: 800004
206+
# Query_time: 0.200123 Lock_time: 0.002700 Rows_sent: 15 Rows_examined: 6500
207+
SET timestamp=1690891224;
208+
SELECT p.name, i.stock_level
209+
FROM products p
210+
JOIN inventory i ON p.id = i.product_id
211+
WHERE i.stock_level BETWEEN 5 AND 15;
212+
# Time: 2023-08-01T12:00:25.007995Z
213+
# User@Host: user4[user4] @ [192.168.1.104] Id: 800005
214+
# Query_time: 0.230789 Lock_time: 0.003100 Rows_sent: 20 Rows_examined: 9000
215+
SET timestamp=1690891225;
216+
SELECT m.sender_id, COUNT(DISTINCT m.receiver_id) as unique_receivers
217+
FROM messages m
218+
GROUP BY m.sender_id
219+
HAVING unique_receivers > 15;

go/keys/keys.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type (
6666
Timestamp int64 `json:"timestamp,omitempty"`
6767
}
6868
QueryFailedResult struct {
69-
Query string
69+
Query string `json:"query"`
7070
LineNumbers []int `json:"lineNumbers"`
7171
Error string `json:"error"`
7272
}

go/keys/keys_test.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"strings"
2222
"testing"
2323

24+
"github.com/stretchr/testify/assert"
2425
"github.com/stretchr/testify/require"
2526

2627
"github.com/vitessio/vt/go/data"
@@ -52,6 +53,13 @@ func TestKeys(t *testing.T) {
5253
},
5354
expectedFile: "../summarize/testdata/slow-query-log.json",
5455
},
56+
{
57+
cfg: Config{
58+
FileName: "../data/testdata/bigger_slow_query_log.log",
59+
Loader: data.SlowQueryLogLoader{},
60+
},
61+
expectedFile: "./testdata/bigger_slow_query_log.json",
62+
},
5563
}
5664

5765
for _, tcase := range cases {
@@ -63,7 +71,10 @@ func TestKeys(t *testing.T) {
6371
out, err := os.ReadFile(tcase.expectedFile)
6472
require.NoError(t, err)
6573

66-
require.Equal(t, string(out), sb.String())
74+
assert.Equal(t, string(out), sb.String())
75+
if t.Failed() {
76+
_ = os.WriteFile(tcase.expectedFile+".correct", []byte(sb.String()), 0o644)
77+
}
6778
})
6879
}
6980
}

0 commit comments

Comments
 (0)