phpmyadmin / phpmyadmin/sql-parser

Parser fails for updates that include subqueries for source tables

未关闭
#269 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug
主要语言
PHP
星标
485
派生
119
PR 合并指标
30 天内没有已合并 PR

描述

The SQL Parser fails to parse the following query:

update `table1` as e, (select * from table2) e2
set
e.`id` = e2.id,
where e.id=e2.id

It returns the output below. This appears to always be an issue when using subqueries in the table references.

[
    {
        "tables": [
            {
                "database": null,
                "table": "table1",
                "column": null,
                "expr": "`table1`",
                "alias": "e",
                "function": null,
                "subquery": null
            }
        ],
        "set": null,
        "where": null,
        "order": null,
        "limit": null,
        "options": {
            "options": []
        },
        "first": 0,
        "last": 10
    },
    {
        "expr": [
            {
                "database": null,
                "table": null,
                "column": null,
                "expr": "*",
                "alias": null,
                "function": null,
                "subquery": null
            }
        ],
        "from": [
            {
                "database": null,
                "table": "table2",
                "column": null,
                "expr": "table2",
                "alias": null,
                "function": null,
                "subquery": null
            }
        ],
        "index_hints": null,
        "partition": null,
        "where": null,
        "group": null,
        "having": null,
        "order": null,
        "limit": null,
        "procedure": null,
        "into": null,
        "join": null,
        "union": [],
        "end_options": null,
        "options": {
            "options": []
        },
        "first": 11,
        "last": 21
    },
    {
        "options": {
            "options": []
        },
        "end_options": null,
        "set": [
            {
                "column": "e.`id`",
                "value": "e2.id"
            }
        ],
        "first": 22,
        "last": 44,
        "where": [
            {
                "identifiers": [
                    "e",
                    "id",
                    "e2"
                ],
                "isOperator": false,
                "expr": "e.id=e2.id"
            }
        ]
    }
]

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,通过 SQL 解析器运行提供的 UPDATE 查询,并将其输出与 issue 中所示的预期 table、subquery、SET 和 WHERE 结构进行比较。跟踪包含 subquery 的 UPDATE 表引用是如何进行词法分析和解析的,然后为此查询添加或更新回归测试,并验证解析后的结构。

由索引模型根据 Issue 内容生成。

评估

技术栈
php, sql
领域
compilers, databases
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。