Hello all,

I am trying to write a utility that processes the results of EXPLAIN QUERY
PLAN statements and presents them in a graphical manner to developers. I
need to extract information from the "detail" column of the returned result
set (e.g. table name, index name, estimated rows etc.) and since the detail
is somewhat verbose I decided to write a small parser to parse it. After
some examination I have come up with the following EBNF:

plan_statement :=
  ( scan |
    search |
    aggregate |
    compound |
    execute |
    use )

scan ::=
  "SCAN" ( "TABLE" ObjectName | "SUBQUERY" int ) ["AS" identifier] [ using
] [ cost ]

search ::=
  "SEARCH" ( "TABLE" ObjectName | "SUBQUERY" int) ["AS" identifier] [ using
] [ filter_expr ] [ cost ]

aggregate ::=
  "USE TEMP B-TREE FOR" aggregate_operation

compound ::=
  "COMPOUND SUBQUERIES" int "AND" int SET_OPERATION

execute ::=
  "EXECUTE" ("LIST" | "CORRELATED SCALAR") "SUBQUERY" int

using ::=
  "USING" (
         "AUTOMATIC" ["COVERING"] "INDEX" |
         ["COVERING"] "INDEX" ObjectName |
         "INTEGER PRIMARY KEY"
        )

cost ::=
  "(~" int "rows)"

aggregate_operation ::=
  ("GROUP BY" | "ORDER BY")

filter_expr ::=
  "(" ColumnName "=" "?" ["AND" ColumnName "=" "?"]* ")"

set_operation ::= ( "UNION" ["ALL"] | "INTERSECT" | "MINUS" | "EXCEPT" )

use ::=
  "USE" ["TEMP"] "B-TREE" FOR ( "GROUP BY" | "ORDER BY" )

ColumnName ::=
  identifier

ObjectName ::=
  identifier

where sequences are separated by spaces, literals are quoted, production
names are unquoted idents, ( ... | ... ) denote choice groups and [ ... ]
denote optional sequences. Productions "identifier" and "int" are omitted
as trivial.

So far this grammar covers plans of all statements I have examined. Could
someone (probably an SQLite developer) tell me if this grammar covers all
cases of "detail" values or if there are cases I have missed? Maybe the
NGQP has introduced some changes I have missed?

Also, regarding object names, do they include database names if
tables/indexes from attached databases are used in the query? (ObjectName
::= [ identifier '.' ]  identifier instead of ObjectName ::= identifier)

Thank you in advance.

--
Constantine
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to