Skip to content

Fix CTE with UNION#62

Merged
StpMax merged 2 commits into
mainfrom
fix-CONN-1340
Aug 6, 2025
Merged

Fix CTE with UNION#62
StpMax merged 2 commits into
mainfrom
fix-CONN-1340

Conversation

@StpMax
Copy link
Copy Markdown
Collaborator

@StpMax StpMax commented Aug 5, 2025

Fix for queries with multiple CTE and UNION in it, like this one:

        WITH ta AS (
            SELECT 'a' AS a
            UNION
            SELECT 'b' AS a
        ), tb AS (
            SELECT 'c' AS a
            UNION
            SELECT 'd' AS a
        )
        SELECT a FROM ta
        UNION
        SELECT a FROM tb

@entelligence-ai-pr-reviews
Copy link
Copy Markdown

Review Summary

🏷️ Draft Comments (1)

Skipped posting 1 draft comments that were valid but scored below your review threshold (>13/15). Feel free to update them here.

mindsdb_sql_parser/parser.py (1)

1112-1118: ctes rule appends to a list using ctes = ctes + [...], which creates a new list each time and can cause O(n^2) time for many CTEs; use ctes.append(...) for O(n) total time.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 5/5
  • Urgency Impact: 2/5
  • Total Score: 9/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sql_parser/parser.py, lines 1112-1118, the `ctes` rule currently appends to the list using `ctes = ctes + [...]`, which is O(n^2) for many CTEs. Change this to use `ctes.append(...)` instead, to ensure O(n) total time for large numbers of CTEs. Preserve the original logic and indentation.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 5, 2025

Coverage

Coverage Report
FileStmtsMissCoverMissing
mindsdb_sql_parser
   __about__.py10100%1–10
   __init__.py1192381%44, 48, 53, 98, 115, 118, 139–158, 165–166
   lexer.py2802192%368, 370, 372, 384, 386, 388, 394–412
   logger.py19479%14, 17, 23, 26
   parser.py11073297%129, 133, 288, 313, 419, 605, 622, 646–647, 868, 922, 999, 1100, 1154, 1164, 1203–1204, 1233, 1244, 1327, 1403, 1442, 1478, 1671–1672, 1847–1848, 2024, 2032, 2085–2088
   utils.py46491%73–79
mindsdb_sql_parser/ast
   base.py36586%13, 28, 31, 46, 51
   create.py801285%23–31, 92–97
   drop.py52296%10, 13
   insert.py63494%39–41, 46
   show.py48198%18
   update.py53591%40–42, 75–76
mindsdb_sql_parser/ast/mindsdb
   knowledge_base.py97199%80
mindsdb_sql_parser/ast/select
   case.py37197%22
   constant.py36197%23
   data.py11464%10–12, 15, 19
   identifier.py831187%56, 104–112, 122
   native_query.py13192%25
   operation.py139497%57, 66, 178, 202
   parameter.py15287%17, 20
   select.py109397%160–165
   star.py12283%8–9
TOTAL339215395% 

Tests Skipped Failures Errors Time
304 0 💤 0 ❌ 0 🔥 12.810s ⏱️

@StpMax StpMax requested a review from ea-rus August 5, 2025 13:31
@StpMax StpMax merged commit 4c9f038 into main Aug 6, 2025
14 checks passed
@StpMax StpMax deleted the fix-CONN-1340 branch August 6, 2025 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants