querycache

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type C

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

C is a query cache, keyed on SQL statement strings (which can contain placeholders).

A cache can be used by multiple threads in parallel; however each different context must use its own Session.

func New

func New(memorySize int64) *C

New creates a query cache of the given size.

func (*C) Add

func (c *C) Add(session *Session, d *CachedData)

Add adds an entry to the cache (possibly evicting some other entry). If the cache already has a corresponding entry for d.SQL, it is updated. Note: d.PrepareMetadata cannot be modified once this method is called.

func (*C) Clear

func (c *C) Clear()

Clear removes all the entries from the cache.

func (*C) Find

func (c *C) Find(session *Session, sql string) (_ CachedData, ok bool)

Find returns the entry for the given query, if it is in the cache.

If any cached data needs to be updated, it must be done via Add. In particular, PrepareMetadata in the returned CachedData must not be modified.

func (*C) Purge

func (c *C) Purge(sql string)

Purge removes the entry for the given query, if it exists.

type CachedData

type CachedData struct {
	SQL  string
	Memo *memo.Memo
	// PrepareMetadata is set for prepare queries. In this case the memo contains
	// unassigned placeholders. For non-prepared queries, it is nil.
	PrepareMetadata *PrepareMetadata
	// IsCorrelated memoizes whether the query contained correlated
	// subqueries during planning (prior to de-correlation).
	IsCorrelated bool
}

CachedData is the data associated with a cache entry.

type PrepareMetadata

type PrepareMetadata struct {
	// Note that AST may be nil if the prepared statement is empty.
	parser.Statement

	// StatementNoConstants is the statement string formatted without constants,
	// suitable for recording in statement statistics.
	StatementNoConstants string

	// Provides TypeHints and Types fields which contain placeholder typing
	// information.
	tree.PlaceholderTypesInfo

	// Columns are the types and names of the query output columns.
	Columns colinfo.ResultColumns

	// InferredTypes represents the inferred types for placeholder, using protocol
	// identifiers. Used for reporting on Describe.
	InferredTypes []oid.Oid
}

PrepareMetadata encapsulates information about a statement that is gathered during Prepare and is later used during Describe or Execute.

func (*PrepareMetadata) MemoryEstimate

func (pm *PrepareMetadata) MemoryEstimate() int64

MemoryEstimate returns an estimation (in bytes) of how much memory is used by the prepare metadata.

type Session

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

Session stores internal information related to a single session. A session cannot be used by multiple threads in parallel.

func (*Session) Init

func (s *Session) Init()

Init initializes or resets a Session.

Jump to

Keyboard shortcuts

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