Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepared statement support #87

Merged
merged 34 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
19fbeb5
Added comPrepare
zachmu Dec 19, 2023
0688042
Define PortalData
zachmu Dec 19, 2023
1c779bf
Another caching change
zachmu Dec 21, 2023
648cadf
Checkpoint
zachmu Dec 21, 2023
e43c495
Close to first draft
zachmu Dec 28, 2023
a52a092
Prepared statement tests
zachmu Dec 28, 2023
b1ba5ab
Convert placeholder nodes
zachmu Dec 28, 2023
15d81a8
Adding object ids to prepare responses
zachmu Dec 28, 2023
37be300
Some fake scaffolding to make more inroads before fixing interfaces
zachmu Jan 2, 2024
e93d747
Bug fixes for bind varsD
zachmu Jan 3, 2024
0a313b2
Merge branch 'main' into zachmu/prepared
zachmu Jan 3, 2024
46fb598
refactoring: split out query / execute
zachmu Jan 3, 2024
f7623c0
Getting closer
zachmu Jan 3, 2024
a1782fd
Destroy the unnamed statement on query
zachmu Jan 3, 2024
70f5701
mising err handling
zachmu Jan 3, 2024
8b24280
Cleanup, added support for the Close message
zachmu Jan 3, 2024
f88dcb3
More prepared statement tests
zachmu Jan 4, 2024
fa8c9b2
Moar tests
zachmu Jan 4, 2024
cf63ea0
Moar tests
zachmu Jan 4, 2024
ce35cbd
Int64 support
zachmu Jan 5, 2024
c88bdad
Added skipped tests for varchar columns with no length
zachmu Jan 5, 2024
b684aa1
Better tests
zachmu Jan 5, 2024
9492d9c
Merge main
zachmu Jan 5, 2024
b02e649
Sorted oid consts
zachmu Jan 10, 2024
483e2cf
Refactoring for redundant testing infra
zachmu Jan 10, 2024
5f3d081
Added skip for broken text type
zachmu Jan 10, 2024
d98b275
Skip a couple more tests
zachmu Jan 10, 2024
46576b6
Development branch for vitess / gms
zachmu Jan 10, 2024
fd60949
Upgrade dolt
zachmu Jan 10, 2024
50442b6
Merge main
zachmu Jan 10, 2024
d2c8503
Bug fix for empty statement
zachmu Jan 10, 2024
4665fbb
Refactored the handleMessage method
zachmu Jan 10, 2024
f6a6159
Formatting
zachmu Jan 10, 2024
fcdaaba
Typo, upgraded deps
zachmu Jan 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 107 additions & 18 deletions postgres/messages/row_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,87 @@ import (
"github.com/dolthub/doltgresql/postgres/connection"
)

const (
OidBool = 16
OidBytea = 17
OidChar = 18
OidName = 19
OidInt8 = 20
OidInt2 = 21
OidInt2Vector = 22
OidInt4 = 23
OidRegproc = 24
OidText = 25
OidOid = 26
OidTid = 27
OidXid = 28
OidCid = 29
OidOidVector = 30
OidPgNodeTree = 194
OidPgString = 1033
zachmu marked this conversation as resolved.
Show resolved Hide resolved
OidPgType = 71
OidPgAttribute = 75
OidPgProc = 81
OidPgClass = 83
OidJson = 114
OidXml = 142
OidXmlArray = 143
OidJsonArray = 199
OidPgNodeTreeArray = 195
OidSmgr = 210
OidIndexAm = 261
OidPoint = 600
OidLseg = 601
OidPath = 602
OidBox = 603
OidPolygon = 604
OidLine = 628
OidFloat4 = 700
OidFloat8 = 701
OidAbstime = 702
OidReltime = 703
OidTinterval = 704
OidUnknown = 705
OidCircle = 718
OidCash = 790
OidMacaddr = 829
OidInet = 869
OidCidr = 650
OidInt2Array = 1005
OidInt4Array = 1007
OidTextArray = 1009
OidByteaArray = 1001
OidVarcharArray = 1015
OidInt8Array = 1016
OidPointArray = 1017
OidJsonArrayArray = 199
OidFloat4Array = 1021
OidFloat8Array = 1022
OidAclitem = 1033
OidAclitemArray = 1034
OidInetArray = 1041
OidCidrArray = 651
OidVarchar = 1043
OidDate = 1082
OidTime = 1083
OidTimestamp = 1114
OidTimestampArray = 1115
OidDateArray = 1182
OidTimeArray = 1183
OidNumeric = 1700
OidRefcursor = 1790
OidRegprocedure = 2202
OidRegoper = 2203
OidRegoperator = 2204
OidRegclass = 2205
OidRegtype = 2206
OidRegrole = 4096
OidRegnamespace = 4097
OidRegnamespaceArray = 4098
OidRegclassArray = 4099
OidRegRoleArray = 4090
)

func init() {
connection.InitializeDefaultMessage(RowDescription{})
}
Expand Down Expand Up @@ -134,50 +215,58 @@ func (m RowDescription) DefaultMessage() *connection.MessageFormat {
return &rowDescriptionDefault
}

// VitessFieldToDataTypeObjectID returns a type, as defined by Vitess, into a type as defined by Postgres.
// VitessFieldToDataTypeObjectID returns the type of a vitess Field into a type as defined by Postgres.
// OIDs can be obtained with the following query: `SELECT oid, typname FROM pg_type ORDER BY 1;`
func VitessFieldToDataTypeObjectID(field *query.Field) (int32, error) {
switch field.Type {
return VitessTypeToObjectID(field.Type)
}

// VitessFieldToDataTypeObjectID returns a type, as defined by Vitess, into a type as defined by Postgres.
// OIDs can be obtained with the following query: `SELECT oid, typname FROM pg_type ORDER BY 1;`
func VitessTypeToObjectID(typ query.Type) (int32, error) {
switch typ {
case query.Type_INT8:
// Postgres doesn't make use of a small integer type for integer returns, which presents a bit of a conundrum.
// GMS defines boolean operations as the smallest integer type, while Postgres has an explicit bool type.
// We can't always assume that `INT8` means bool, since it could just be a small integer. As a result, we'll
// always return this as though it's an `INT32`, which also means that we can't support bools right now.
// OIDs 16 (bool) and 18 (char, ASCII only?) are the only single-byte types as far as I'm aware.
return 23, nil
return OidInt4, nil
case query.Type_INT16:
// The technically correct OID is 21 (2-byte integer), however it seems like some clients don't actually expect
// this, so I'm not sure when it's actually used by Postgres. Because of this, we'll just pretend it's an `INT32`.
return 23, nil
return OidInt4, nil
case query.Type_INT24:
// Postgres doesn't have a 3-byte integer type, so just pretend it's `INT32`.
return 23, nil
return OidInt4, nil
case query.Type_INT32:
return 23, nil
return OidInt4, nil
case query.Type_INT64:
return 20, nil
return OidInt8, nil
case query.Type_FLOAT32:
return 700, nil
return OidFloat4, nil
case query.Type_FLOAT64:
return 701, nil
return OidFloat8, nil
case query.Type_DECIMAL:
return 1700, nil
return OidNumeric, nil
case query.Type_CHAR:
return 1042, nil
return OidChar, nil
case query.Type_VARCHAR:
return 1043, nil
return OidVarchar, nil
case query.Type_TEXT:
return 25, nil
return OidText, nil
case query.Type_JSON:
return 114, nil
return OidJson, nil
case query.Type_TIMESTAMP, query.Type_DATETIME:
return 1114, nil
const OidTimestamp = 1114
return OidTimestamp, nil
case query.Type_DATE:
return 1082, nil
const OidDate = 1082
return OidDate, nil
case query.Type_NULL_TYPE:
return 25, nil // NULL is treated as TEXT on the wire
return OidText, nil // NULL is treated as TEXT on the wire
default:
return 0, fmt.Errorf("unsupported type returned from engine: %s", field.Type)
return 0, fmt.Errorf("unsupported type: %s", typ)
}
}

Expand Down
5 changes: 3 additions & 2 deletions server/ast/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,9 @@ func nodeExpr(node tree.Expr) (vitess.Expr, error) {
case *tree.PartitionMinVal:
return nil, fmt.Errorf("MINVALUE is not yet supported")
case *tree.Placeholder:
//TODO: figure out if I can delete this
panic("this should probably be deleted (internal error, Placeholder)")
// TODO: deal with type annotation
zachmu marked this conversation as resolved.
Show resolved Hide resolved
mysqlBindVarIdx := node.Idx + 1
return vitess.NewValArg([]byte(fmt.Sprintf(":v%d", mysqlBindVarIdx))), nil
case *tree.RangeCond:
operator := vitess.BetweenStr
if node.Not {
Expand Down
18 changes: 17 additions & 1 deletion server/converted_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package server

import vitess "github.com/dolthub/vitess/go/vt/sqlparser"
import (
"github.com/dolthub/go-mysql-server/sql"
querypb "github.com/dolthub/vitess/go/vt/proto/query"
vitess "github.com/dolthub/vitess/go/vt/sqlparser"
)

// ConvertedQuery represents a query that has been converted from the Postgres representation to the Vitess
// representation. String may contain the string version of the converted query. AST will contain the tree
Expand All @@ -24,3 +28,15 @@ type ConvertedQuery struct {
String string
AST vitess.Statement
}

type PreparedStatementData struct {
Query ConvertedQuery
ReturnFields []*querypb.Field
BindVarTypes []int32
}

type PortalData struct {
Query ConvertedQuery
Fields []*querypb.Field
BoundPlan sql.Node
}
66 changes: 0 additions & 66 deletions server/implicit_commit.go

This file was deleted.

Loading
Loading