-
Notifications
You must be signed in to change notification settings - Fork 5k
feat: add query phase tracking for SHOW QUERIES #34706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yihaoDeng
wants to merge
33
commits into
3.0
Choose a base branch
from
feat/addShowQuery
base: 3.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+748
−160
Open
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
54645cb
feat: add query phase tracking for SHOW QUERIES
yihaoDeng a9bd508
fix invalid rm
yihaoDeng 63ec536
fix: complete query phase tracking with proper EQueryExecPhase enum
yihaoDeng f98d340
feat: add startTs/endTs timing fields to sub-task in SHOW QUERIES
yihaoDeng f39d9d5
update test case
yihaoDeng 0a92a5e
update python
yihaoDeng e03c928
feat: improve sub_status display in SHOW QUERIES
yihaoDeng 8490ab6
fix problem
yihaoDeng c98b454
fix: add NULL check for taosArrayGet and remove unused import
yihaoDeng a6aa608
refactor: rename current_phase to phase_name for consistency with pha…
yihaoDeng af68031
refactor: rename phase_name to phase_state for better semantics
yihaoDeng 51c1a6f
style: format code for consistency and readability
yihaoDeng da959b3
style: format code for consistency and readability
yihaoDeng 4dff055
Merge branch 'feat/addShowQuery' of https://github.com/taosdata/TDeng…
yihaoDeng 0b78fe6
style: format code for consistency and readability
yihaoDeng 652f5f3
refactor code
yihaoDeng 8f0704c
refactor code
yihaoDeng 5f5dc9e
Merge remote-tracking branch 'origin/3.0' into feat/addShowQuery
yihaoDeng 3882cd8
Merge remote-tracking branch 'origin/3.0' into feat/addShowQuery
yihaoDeng 8d9d7b5
update doc
yihaoDeng 464ba76
Update docs/zh/14-reference/03-taos-sql/51-perf.md
yihaoDeng a8e8ceb
Add query execution phase tracking and update related tests
yihaoDeng bf8b384
fix: resolve multiple issues in query phase tracking
yihaoDeng ea20d0f
feat: add execute:waiting phase for scan-to-merge transition
yihaoDeng 5927817
revert doc
yihaoDeng b49f350
update query track
yihaoDeng e0a208b
fix: only update phaseStartTime when phase actually changes
yihaoDeng cf0d57f
Merge remote-tracking branch 'origin/3.0' into feat/addShowQuery
yihaoDeng 373445c
feat: refine sub_status and add branch design notes
yihaoDeng 845c243
revert: remove branch design notes document
yihaoDeng e507581
refactor: unify phase sub-state format to slash style
yihaoDeng 4081511
Merge remote-tracking branch 'origin/3.0' into feat/addShowQuery
yihaoDeng cfbf4a8
Potential fix for pull request finding
yihaoDeng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| import time | ||
| import platform | ||
yihaoDeng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| from new_test_framework.utils import tdLog, tdSql, sc, clusterComCheck, tdCom | ||
yihaoDeng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| 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. | ||
| """ | ||
yihaoDeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
|
|
||
yihaoDeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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]") | ||
yihaoDeng marked this conversation as resolved.
Show resolved
Hide resolved
yihaoDeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
|
|
||
yihaoDeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
yihaoDeng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
yihaoDeng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| print("test phase timing accuracy ....................... [passed]") | ||
|
|
||
| def cleanup_class(cls): | ||
yihaoDeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| tdLog.info(f"cleanup {__file__}") | ||
| tdSql.execute(f"drop database if exists db") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.