backend

package
v0.0.0-...-dd6d791 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Overview

Copyright 2024-2025 ApeCloud, Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024-2025 ApeCloud, Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024-2025 ApeCloud, Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyQueryRowLimit

func ApplyQueryRowLimit(ctx *sql.Context, schema sql.Schema, iter sql.RowIter) sql.RowIter

ApplyQueryRowLimit wraps result rows with the limit configured on the current session. Non-row results and sessions with no limit are unchanged.

func IsPureDataQuery

func IsPureDataQuery(ctx *sql.Context, n sql.Node) bool

IsPureDataQuery inspects if the plan is a pure data query, i.e., it operates on (>=1) data tables and does not touch any system tables. The following examples are NOT pure data queries: - `SELECT * FROM mysql.*` - `TRUNCATE mysql.user` - `SELECT DATABASE()`

func IsWriteQueryText

func IsWriteQueryText(query string) bool

IsWriteQueryText classifies statements that could not be parsed by the protocol-specific engine. Parsed statements should use their AST instead.

func NewSessionBuilder

func NewSessionBuilder(provider *catalog.DatabaseProvider, opts ...SessionOption) func(ctx context.Context, conn *mysql.Conn, addr string) (sql.Session, error)

NewSessionBuilder returns a session builder for the given database provider.

func QueryForJSONScan

func QueryForJSONScan(query string, schema sql.Schema) string

QueryForJSONScan casts JSON result columns to VARCHAR before the DuckDB Go driver can collapse JSON null into SQL NULL.

func RemoveAllPipes

func RemoveAllPipes(dataDir string) error

func RewriteIncomingQuery

func RewriteIncomingQuery(query string) string

RewriteIncomingQuery applies the default request modifiers. Tests and protocol handlers use this so replica-dump DDL is rewritten the same way as live MySQL connections.

func WrapHandler

func WrapHandler(
	provider *catalog.DatabaseProvider,
	engine *sqle.Engine,
	newContext func(context.Context, *mysql.Conn, string) (*sql.Context, error),
	readOnly bool,
) server.HandlerWrapper

Types

type DuckBuilder

type DuckBuilder struct {
	FlushDeltaBuffer func(*sql.Context) error
	// contains filtered or unexported fields
}

func NewDuckBuilder

func NewDuckBuilder(base *rowexec.BaseBuilder, provider *catalog.DatabaseProvider) *DuckBuilder

func NewEngine

func NewEngine(provider *catalog.DatabaseProvider) (*sqle.Engine, *DuckBuilder)

NewEngine constructs the MySQL engine with MyDuck's parser and executor compatibility boundaries installed consistently.

func (*DuckBuilder) Build

func (b *DuckBuilder) Build(ctx *sql.Context, root sql.Node, r sql.Row) (iter sql.RowIter, err error)

func (*DuckBuilder) CreatePipe

func (h *DuckBuilder) CreatePipe(ctx *sql.Context, subdir string) (string, error)

func (*DuckBuilder) Provider

func (b *DuckBuilder) Provider() *catalog.DatabaseProvider

type MyHandler

type MyHandler struct {
	*server.Handler
	// contains filtered or unexported fields
}

func (*MyHandler) ComBind

func (h *MyHandler) ComBind(ctx context.Context, c *mysql.Conn, query string, parsedQuery mysql.ParsedQuery, prepare *mysql.PrepareData) (mysql.BoundQuery, []*querypb.Field, error)

func (*MyHandler) ComExecuteBound

func (h *MyHandler) ComExecuteBound(ctx context.Context, c *mysql.Conn, query string, boundQuery mysql.BoundQuery, callback mysql.ResultSpoolFn) (returnErr error)

func (*MyHandler) ComInitDB

func (h *MyHandler) ComInitDB(c *mysql.Conn, schemaName string) error

func (*MyHandler) ComMultiQuery

func (h *MyHandler) ComMultiQuery(
	ctx context.Context,
	c *mysql.Conn,
	query string,
	callback mysql.ResultSpoolFn,
) (rest string, returnErr error)

func (*MyHandler) ComParsedQuery

func (h *MyHandler) ComParsedQuery(ctx context.Context, c *mysql.Conn, query string, parsed sqlparser.Statement, callback mysql.ResultSpoolFn) (returnErr error)

func (*MyHandler) ComPrepare

func (h *MyHandler) ComPrepare(ctx context.Context, c *mysql.Conn, query string, prepare *mysql.PrepareData) ([]*querypb.Field, error)

func (*MyHandler) ComPrepareParsed

func (h *MyHandler) ComPrepareParsed(ctx context.Context, c *mysql.Conn, query string, parsed sqlparser.Statement, prepare *mysql.PrepareData) (mysql.ParsedQuery, []*querypb.Field, error)

func (*MyHandler) ComQuery

func (h *MyHandler) ComQuery(
	ctx context.Context,
	c *mysql.Conn,
	query string,
	callback mysql.ResultSpoolFn,
) (returnErr error)

Naive query rewriting. This is just a temporary solution and should be replaced with a more robust implementation.

func (*MyHandler) ComStmtExecute

func (h *MyHandler) ComStmtExecute(ctx context.Context, c *mysql.Conn, prepare *mysql.PrepareData, callback func(*sqltypes.Result) error) (returnErr error)

func (*MyHandler) ConnectionClosed

func (h *MyHandler) ConnectionClosed(c *mysql.Conn)

type QueryAudit

type QueryAudit struct {
	// contains filtered or unexported fields
}

QueryAudit records the outcome of one ordinary protocol query.

func NewQueryAudit

func NewQueryAudit(conn *mysql.Conn, protocol, query string) *QueryAudit

NewQueryAudit starts an audit record for a user-facing protocol query.

func (*QueryAudit) AddRows

func (audit *QueryAudit) AddRows(rows int)

AddRows records rows successfully handed to the protocol callback.

func (*QueryAudit) Complete

func (audit *QueryAudit) Complete(err error)

Complete emits the query's single structured audit record.

type RequestModifier

type RequestModifier func(string, *[]ResultModifier) string

RequestModifier is a function type that transforms a query string

type ResultModifier

type ResultModifier func(*sqltypes.Result) *sqltypes.Result

ResultModifier transforms a Result.

type SQLRowIter

type SQLRowIter struct {
	// contains filtered or unexported fields
}

SQLRowIter wraps a standard sql.Rows as a RowIter.

func NewSQLRowIter

func NewSQLRowIter(rows *stdsql.Rows, schema sql.Schema) (*SQLRowIter, error)

func (*SQLRowIter) Close

func (iter *SQLRowIter) Close(ctx *sql.Context) error

Close closes the underlying sql.Rows.

func (*SQLRowIter) Next

func (iter *SQLRowIter) Next(ctx *sql.Context) (sql.Row, error)

Next retrieves the next row. It will return io.EOF if it's the last row.

type Session

type Session struct {
	*memory.Session
	// contains filtered or unexported fields
}

func NewSession

func NewSession(base *memory.Session, provider *catalog.DatabaseProvider, opts ...SessionOption) *Session

func (*Session) CloseConn

func (sess *Session) CloseConn()

CloseConn implements adapter.ConnectionHolder.

func (*Session) CloseTxn

func (sess *Session) CloseTxn()

CloseTxn implements adapter.ConnectionHolder.

func (*Session) CommitTransaction

func (sess *Session) CommitTransaction(ctx *sql.Context, tx sql.Transaction) error

CommitTransaction implements sql.TransactionSession.

func (*Session) CurrentSchemaOfUnderlyingConn

func (sess *Session) CurrentSchemaOfUnderlyingConn() string

func (*Session) ExecContext

func (sess *Session) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error)

func (*Session) GetCatalogConn

func (sess *Session) GetCatalogConn(ctx context.Context) (*stdsql.Conn, error)

GetCatalogConn implements adapter.ConnectionHolder.

func (*Session) GetCatalogTxn

func (sess *Session) GetCatalogTxn(ctx context.Context, options *stdsql.TxOptions) (*stdsql.Tx, error)

GetCatalogTxn implements adapter.ConnectionHolder.

func (*Session) GetConn

func (sess *Session) GetConn(ctx context.Context) (*stdsql.Conn, error)

GetConn implements adapter.ConnectionHolder.

func (*Session) GetCurrentCatalog

func (sess *Session) GetCurrentCatalog() string

GetCurrentCatalog implements adapter.ConnectionHolder.

func (*Session) GetCurrentSchema

func (sess *Session) GetCurrentSchema() string

GetCurrentSchema implements adapter.ConnectionHolder.

func (*Session) GetPersistedValue

func (sess *Session) GetPersistedValue(k string) (interface{}, error)

GetPersistedValue implements sql.PersistableSession.

func (*Session) GetTxn

func (sess *Session) GetTxn(ctx context.Context, options *stdsql.TxOptions) (*stdsql.Tx, error)

GetTxn implements adapter.ConnectionHolder.

func (*Session) PersistGlobal

func (sess *Session) PersistGlobal(ctx *sql.Context, sysVarName string, value interface{}) error

PersistGlobal implements sql.PersistableSession.

func (*Session) Provider

func (sess *Session) Provider() *catalog.DatabaseProvider

Provider returns the database provider for the session.

func (*Session) QueryRow

func (sess *Session) QueryRow(ctx context.Context, query string, args ...any) *stdsql.Row

func (*Session) QueryRowLimit

func (sess *Session) QueryRowLimit() uint64

QueryRowLimit returns the maximum number of rows a query may return. Zero means unlimited.

func (*Session) RemoveAllPersistedGlobals

func (sess *Session) RemoveAllPersistedGlobals() error

RemoveAllPersistedGlobals implements sql.PersistableSession.

func (*Session) RemovePersistedGlobal

func (sess *Session) RemovePersistedGlobal(sysVarName string) error

RemovePersistedGlobal implements sql.PersistableSession.

func (*Session) Rollback

func (sess *Session) Rollback(ctx *sql.Context, tx sql.Transaction) error

Rollback implements sql.TransactionSession.

func (*Session) SetSessionVariable

func (sess *Session) SetSessionVariable(ctx *sql.Context, name string, value interface{}) error

func (*Session) StartTransaction

func (sess *Session) StartTransaction(ctx *sql.Context, tCharacteristic sql.TransactionCharacteristic) (sql.Transaction, error)

StartTransaction implements sql.TransactionSession.

func (*Session) TryGetTxn

func (sess *Session) TryGetTxn() *stdsql.Tx

TryGetTxn implements adapter.ConnectionHolder.

type SessionOption

type SessionOption func(*Session)

func WithQueryRowLimit

func WithQueryRowLimit(limit uint64) SessionOption

WithQueryRowLimit limits the number of rows returned by queries in a session. A limit of zero leaves query results unlimited.

type Transaction

type Transaction struct {
	memory.Transaction
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL