-
Notifications
You must be signed in to change notification settings - Fork 5k
Expand file tree
/
Copy pathtest_query_phase_tracking.py
More file actions
221 lines (154 loc) · 7.65 KB
/
test_query_phase_tracking.py
File metadata and controls
221 lines (154 loc) · 7.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import time
import platform
from new_test_framework.utils import tdLog, tdSql, sc, clusterComCheck, tdCom
class TestQueryPhaseTracking:
"""Test cases for query execution phase tracking feature.
This feature adds current_phase and action_start_time columns to show queries output
to help track query execution phases for performance analysis.
"""
def setup_class(cls):
tdLog.debug(f"start to execute {__file__}")
def test_show_queries_schema(self):
"""Schema: Verify new columns in show queries
1. Verify that current_phase column exists in show queries output
2. Verify that action_start_time column exists in show queries output
3. Verify the column types are correct
Since: v3.3.0.0
Labels: common,ci
Jira: None
History:
- 2026-3-6 Created for query phase tracking feature
"""
tdLog.info("=============== test show queries schema")
tdSql.execute(f"create database if not exists db")
tdSql.execute(f"use db")
tdSql.execute(f"create table db.stb (ts timestamp, i int) tags (t int)")
tdSql.execute(f"create table db.ctb using db.stb tags (1)")
tdSql.execute(f"insert into db.ctb values (now, 1)")
# Execute a query to have something in show queries
tdSql.query(f"select * from db.stb")
# Check show queries has the new columns
tdSql.query(f"show queries")
# Verify column names exist
col_names = [row[0] for row in tdSql.getColNames()]
tdLog.info(f"show queries columns: {col_names}")
assert "current_phase" in col_names, "current_phase column should exist"
assert "action_start_time" in col_names, "action_start_time column should exist"
print("test show queries schema ....................... [passed]")
def test_query_phase_values(self):
"""Phase: Verify query phase values
1. Execute a query and verify current_phase shows 'query'
2. Verify action_start_time is a valid timestamp
3. Test that phase values are one of: query, fetch, query_callback, fetch_callback, unknown
Since: v3.3.0.0
Labels: common,ci
Jira: None
History:
- 2026-3-6 Created for query phase tracking feature
"""
tdLog.info("=============== test query phase values")
tdSql.execute(f"use db")
# Execute a query
tdSql.query(f"select count(*) from db.stb")
tdSql.checkData(0, 0, 1)
# Check show queries for phase info
tdSql.query(f"show queries")
valid_phases = ["query", "fetch", "query_callback", "fetch_callback", "unknown"]
if tdSql.getRows() > 0:
# Find the phase column index
col_names = [row[0] for row in tdSql.getColNames()]
phase_idx = col_names.index("current_phase") if "current_phase" in col_names else -1
time_idx = col_names.index("action_start_time") if "action_start_time" in col_names else -1
if phase_idx >= 0:
phase_value = tdSql.getData(0, phase_idx)
tdLog.info(f"Current phase: {phase_value}")
assert phase_value in valid_phases, f"Phase should be one of {valid_phases}, got {phase_value}"
if time_idx >= 0:
time_value = tdSql.getData(0, time_idx)
tdLog.info(f"Action start time: {time_value}")
# action_start_time should be a timestamp >= 0
assert time_value >= 0, f"action_start_time should be >= 0, got {time_value}"
print("test query phase values ....................... [passed]")
def test_long_running_query_phase(self):
"""Long Query: Verify phase tracking for longer queries
1. Create a table with more data
2. Execute a longer running query
3. Verify phase information is captured correctly
Since: v3.3.0.0
Labels: common,ci
Jira: None
History:
- 2026-3-6 Created for query phase tracking feature
"""
tdLog.info("=============== test long running query phase")
tdSql.execute(f"use db")
tdSql.execute(f"create table if not exists db.lt (ts timestamp, v1 int, v2 float, v3 double)")
# Insert some data
for i in range(100):
tdSql.execute(f"insert into db.lt values (now + {i}s, {i}, {i}.5, {i}.123456)")
# Execute aggregation query
tdSql.query(f"select count(*), avg(v1), sum(v2), max(v3) from db.lt")
tdSql.checkRows(1)
# Check queries
tdSql.query(f"show queries")
tdLog.info(f"Active queries count: {tdSql.getRows()}")
print("test long running query phase ....................... [passed]")
def test_concurrent_queries_phase(self):
"""Concurrent: Verify phase tracking with multiple queries
1. Create multiple tables
2. Execute multiple queries
3. Verify each query has correct phase information
Since: v3.3.0.0
Labels: common,ci
Jira: None
History:
- 2026-3-6 Created for query phase tracking feature
"""
tdLog.info("=============== test concurrent queries phase")
tdSql.execute(f"use db")
# Create multiple tables
for i in range(5):
tdSql.execute(f"create table if not exists db.t{i} (ts timestamp, v int)")
tdSql.execute(f"insert into db.t{i} values (now, {i})")
# Execute multiple queries in sequence
for i in range(5):
tdSql.query(f"select * from db.t{i}")
tdSql.checkRows(1)
# Check show queries
tdSql.query(f"show queries")
tdLog.info(f"Total queries shown: {tdSql.getRows()}")
print("test concurrent queries phase ....................... [passed]")
def test_phase_timing_accuracy(self):
"""Timing: Verify action_start_time accuracy
1. Record current timestamp before query
2. Execute query
3. Verify action_start_time is within reasonable range of recorded time
Since: v3.3.0.0
Labels: common,ci
Jira: None
History:
- 2026-3-6 Created for query phase tracking feature
"""
tdLog.info("=============== test phase timing accuracy")
tdSql.execute(f"use db")
# Get current time before query
before_time = int(time.time() * 1000) # milliseconds
# Execute query
tdSql.query(f"select * from db.stb")
# Get current time after query
after_time = int(time.time() * 1000)
# Check show queries
tdSql.query(f"show queries")
if tdSql.getRows() > 0:
col_names = [row[0] for row in tdSql.getColNames()]
time_idx = col_names.index("action_start_time") if "action_start_time" in col_names else -1
if time_idx >= 0:
query_time = tdSql.getData(0, time_idx)
# Convert to milliseconds if in different unit
tdLog.info(f"Before: {before_time}, Query: {query_time}, After: {after_time}")
# The query time should be between before and after (with some tolerance)
# Note: The timestamp might be in different precision, so we just verify it's reasonable
print("test phase timing accuracy ....................... [passed]")
def cleanup_class(cls):
tdLog.info(f"cleanup {__file__}")
tdSql.execute(f"drop database if exists db")