phpmyadmin / phpmyadmin/sql-parser

Subquery in expressions support

Open
#298 2 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug enhancement
Dominant language
PHP
Stars
485
Forks
119
PR merge metrics
No merged PRs in 30d

Description

It seems to subqueries are poorly supported

Some examples first:

They are not parsed at all
SELECT * FROM (SELECT * FROM b) a

results in

...
PhpMyAdmin\SqlParser\Components\Expression Object
(
    [database] =>
    [table] =>
    [column] =>
    [expr] => (SELECT * FROM b)
    [alias] => a
    [function] =>
    [subquery] => SELECT
)
...
not even extracted properly (see #254)
SELECT * FROM a WHERE a.field IN (SELECT * FROM b)

results in

...
...
PhpMyAdmin\SqlParser\Components\Condition Object
(
    [identifiers] => Array
        (
            [0] => a
            [1] => field
            [2] => b
        )

    [isOperator] =>
    [expr] => a.field IN (SELECT * FROM b)
)
...

So I have an idea. May be there must be separate ExpressionParser generating AST for expression? Those (including me) who needed parsed expression can use it (and extract subselects, and parse it with regular parser), and there will be no compatibility break.

Does it sounds as a good plan? If it does, I would like to implement it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the existing expression-parsing path and the regular parser described in the examples. Determine how a separate ExpressionParser could represent and extract subqueries while preserving compatibility, then verify the SELECT and WHERE IN examples produce usable parsed subqueries.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, sql
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.