Implement explain (query plan) statements, ala sqlite
This commit is contained in:
parent
c842cf50b6
commit
ab82249523
|
@ -1712,6 +1712,7 @@ statementWithoutSemicolon =
|
|||
,rollback
|
||||
,grant
|
||||
,revoke
|
||||
,explain
|
||||
,SelectStatement <$> queryExpr
|
||||
]
|
||||
|
||||
|
@ -2168,6 +2169,14 @@ privilegeObject = choice
|
|||
,optional (keyword_ "table") >> PrivTable <$> names "table name"
|
||||
]
|
||||
|
||||
explain :: Parser Statement
|
||||
explain = do
|
||||
keyword_ "explain" >>
|
||||
Explain
|
||||
<$> isJust <$> optional (keywords_ ["query", "plan"])
|
||||
<*> statementWithoutSemicolon
|
||||
|
||||
|
||||
|
||||
{-
|
||||
----------------------------
|
||||
|
|
|
@ -681,6 +681,10 @@ statement _ (RevokeRole ao rs trs db) =
|
|||
adminOptFor AdminOptionFor = texts ["admin","option","for"]
|
||||
adminOptFor NoAdminOptionFor = mempty
|
||||
|
||||
statement dialect (Explain explainQueryPlan inner) =
|
||||
pretty "explain"
|
||||
<+> (if explainQueryPlan then pretty "query plan" else mempty)
|
||||
<+> statement dialect inner
|
||||
|
||||
statement _ (StatementComment cs) = vsep $ map comment cs
|
||||
statement _ EmptyStatement = mempty
|
||||
|
|
|
@ -523,10 +523,20 @@ data Statement =
|
|||
| SetNames
|
||||
| SetTransform
|
||||
| SetCollation -}
|
||||
| Explain
|
||||
-- When enabled, this corresponds to the higher level
|
||||
-- "EXPLAIN QUERY PLAN" statement
|
||||
{esExplainQueryPlan :: Bool
|
||||
-- Technically a sqlite "explain" cannot be followed by another explain
|
||||
-- statement, but I think this representation is good enough...
|
||||
,esStatement :: Statement
|
||||
}
|
||||
| StatementComment [Comment]
|
||||
| EmptyStatement
|
||||
deriving (Eq,Show,Read,Data,Typeable)
|
||||
|
||||
|
||||
|
||||
data DropBehaviour =
|
||||
Restrict
|
||||
| Cascade
|
||||
|
@ -720,6 +730,7 @@ data PrivilegeAction =
|
|||
| PrivExecute
|
||||
deriving (Eq,Show,Read,Data,Typeable)
|
||||
|
||||
|
||||
-- | Comment. Useful when generating SQL code programmatically. The
|
||||
-- parser doesn't produce these.
|
||||
newtype Comment = BlockComment Text
|
||||
|
|
|
@ -775,6 +775,18 @@ defintely skip
|
|||
$ ColDefaultClause
|
||||
$ DefaultClause $ NumLit "2"]]
|
||||
False
|
||||
,testStatement ansi2011
|
||||
"explain create table t (a int);"
|
||||
$ Explain False
|
||||
$ CreateTable [Name Nothing "t"]
|
||||
[TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) []]
|
||||
False
|
||||
,testStatement ansi2011
|
||||
"explain query plan create table t (a int);"
|
||||
$ Explain True
|
||||
$ CreateTable [Name Nothing "t"]
|
||||
[TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) []]
|
||||
False
|
||||
|
||||
|
||||
{-
|
||||
|
|
Loading…
Reference in a new issue