Support batch query with parameter #287
jingchen2222
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Motivation
In database management systems (DBMS), a prepared statement or parameterized statement is a feature used to execute the same or similar database statements repeatedly with high efficiency. Typically used with SQL statements such as queries or updates, the prepared statement takes the form of a template into which certain constant values are substituted during each execution.[1]
As compared to executing statements directly, prepared statements offer two main advantages:
We are trying to support query with given parameters under
batch-mode
Example
This example uses Java and JDBC for MYSQL database.
HybridSE currently support using PrepareStatement to INSERT rows into the table. In this article, we are trying to support query SQL with PrepareStatement.
Design & Implementation
SQL Syntax
Parameterized query statement has been supported in
ZETASQL
parser.Parameter Representation.
Resolved By https://github.com/4paradigm/HybridSE/pull/182
Data structure
We are going to use
ParameterExpr
Node to represent a placeholder instead of using aConstNode
.ParamterExpr
node maintains a fieldposition_
to identify the parameter's position (index).Convert Parameterized QueryStatement into SQL trees and Logical Plan.
The implementation is quite straight forward. Convert
zetasql::ASTParameterExpr
toParamterExpr
.Check ISSUE #181 for more details.
Implement Plan
Resolved by https://github.com/4paradigm/HybridSE/pull/186
Schema Infer for Query with parameters types.
ParamterExpr
: extract parameter types from parameter_schema_ which has been store in Plan context.CodeGen https://github.com/4paradigm/HybridSE/pull/187
Modify
RowFnLetIRBuilder
@parameter
argurement to function let.@paramter
valueBuild LLVM IR for
ParameterExpr
ParameterExpr
value from@parameter
row.@parameter
Engine and Runner #262
Runner Implementation
We have to support query statements with parameters which means we should design and implement interface to run with given parameter row.
SDK
SQL router #248
Demo
JDBC #167
Performance
Reference
https://en.wikipedia.org/wiki/Prepared_statement
Beta Was this translation helpful? Give feedback.
All reactions