Implement explain (query plan) statements, ala sqlite
This commit is contained in:
parent
c842cf50b6
commit
ab82249523
|
@ -1712,6 +1712,7 @@ statementWithoutSemicolon =
|
||||||
,rollback
|
,rollback
|
||||||
,grant
|
,grant
|
||||||
,revoke
|
,revoke
|
||||||
|
,explain
|
||||||
,SelectStatement <$> queryExpr
|
,SelectStatement <$> queryExpr
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -2168,6 +2169,14 @@ privilegeObject = choice
|
||||||
,optional (keyword_ "table") >> PrivTable <$> names "table name"
|
,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 AdminOptionFor = texts ["admin","option","for"]
|
||||||
adminOptFor NoAdminOptionFor = mempty
|
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 _ (StatementComment cs) = vsep $ map comment cs
|
||||||
statement _ EmptyStatement = mempty
|
statement _ EmptyStatement = mempty
|
||||||
|
|
|
@ -523,10 +523,20 @@ data Statement =
|
||||||
| SetNames
|
| SetNames
|
||||||
| SetTransform
|
| SetTransform
|
||||||
| SetCollation -}
|
| 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]
|
| StatementComment [Comment]
|
||||||
| EmptyStatement
|
| EmptyStatement
|
||||||
deriving (Eq,Show,Read,Data,Typeable)
|
deriving (Eq,Show,Read,Data,Typeable)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data DropBehaviour =
|
data DropBehaviour =
|
||||||
Restrict
|
Restrict
|
||||||
| Cascade
|
| Cascade
|
||||||
|
@ -720,6 +730,7 @@ data PrivilegeAction =
|
||||||
| PrivExecute
|
| PrivExecute
|
||||||
deriving (Eq,Show,Read,Data,Typeable)
|
deriving (Eq,Show,Read,Data,Typeable)
|
||||||
|
|
||||||
|
|
||||||
-- | Comment. Useful when generating SQL code programmatically. The
|
-- | Comment. Useful when generating SQL code programmatically. The
|
||||||
-- parser doesn't produce these.
|
-- parser doesn't produce these.
|
||||||
newtype Comment = BlockComment Text
|
newtype Comment = BlockComment Text
|
||||||
|
|
|
@ -775,6 +775,18 @@ defintely skip
|
||||||
$ ColDefaultClause
|
$ ColDefaultClause
|
||||||
$ DefaultClause $ NumLit "2"]]
|
$ DefaultClause $ NumLit "2"]]
|
||||||
False
|
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