queryprofile

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package queryprofile carries request-owned observation across callback registries without a dependency on the Cypher executor or its plan types.

Index

Constants

View Source
const (
	// KindTemporalEligibilityRequest names one returned current-version decision.
	KindTemporalEligibilityRequest = "TemporalEligibilityRequest"
	// KindNodeBatchByIDSeek is one bulk node-image acquisition.
	KindNodeBatchByIDSeek = "NodeBatchByIdSeek"
	// KindSchemaConstraintCatalog is one acquisition of schema constraints.
	KindSchemaConstraintCatalog = "SchemaConstraintCatalog"
	// KindAllNodesScan names the read of the whole node population.
	KindAllNodesScan = "AllNodesScan"
	// KindAllRelationshipsScan names the read of the whole relationship
	// population.
	KindAllRelationshipsScan = "AllRelationshipsScan"
	// KindNodeByLabelScan names the read of the nodes of one label.
	KindNodeByLabelScan = "NodeByLabelScan"
	// KindNodeByIDSeek names the point read of one node by id. The value keeps
	// the plan operator's spelling, NodeByIdSeek.
	KindNodeByIDSeek = "NodeByIdSeek"
	// KindRelationshipByTypeScan names the delivered relationship population of one type.
	KindRelationshipByTypeScan = "RelationshipByTypeScan"
	// KindRelationshipByIDSeek names a point read of one relationship by id.
	KindRelationshipByIDSeek = "RelationshipByIdSeek"
)

The profile ledger names a physical read by what the reader read, not by the operator that asked for it: AllNodesScan reads every node, NodeByLabelScan the nodes of one label, NodeByIDSeek one node by id, AllRelationshipsScan every relationship. These are the kinds an execution and the packages it calls both report, so they are canonical here and every reporter spells them through these constants, one read never appearing under two spellings. A kind this file does not name belongs to the one owner that reads it.

Variables

This section is empty.

Functions

func Callback

func Callback(ctx context.Context, category, name string)

Callback is called when an actual callback is invoked, not during lookup or planning. Ordinary calls allocate no profiling state or formatted messages.

func EntityPopulation

func EntityPopulation[T any](ctx context.Context, kind, detail string, entities []*T)

EntityPopulation records the entities a bulk read actually returned: each non-nil entry of entities is one entity read and one row. It records them where the read handed them over, before any consumer narrows the population, and an empty population the consumer did receive records a known zero rather than no record at all.

A statement without an observer returns before traversing entries or allocating, so an ordinary statement pays one observer lookup and nothing else.

func EntityReadResult

func EntityReadResult[T any](counter *ReadCounter, entity *T, err error)

EntityReadResult records the outcome of one actual point-read attempt. A successful non-nil image is one row; absence/failure is zero rows. The attempt is one logical request, independently of fields or payload decoded by storage. Invoke only after the reader ran; an unused capability is not an attempt.

func EntityVisitor

func EntityVisitor[T any](ctx context.Context, kind, detail string, visit func(*T) error) func(*T) error

EntityVisitor observes the entities a streaming read hands to its consumer, before that consumer filters any of them, and returns the callback the read streams through: visit itself when the statement has no observer, so an ordinary statement allocates no wrapper, and otherwise a wrapper that counts each non-nil entity as one entity read and one row before calling visit.

func OnLifetime

func OnLifetime(lifetime context.Context, scope context.Context) context.Context

OnLifetime transfers observation attribution to independently owned work. Request cancellation and request values are not inherited. Ordinary work without an observer returns lifetime directly and allocates nothing.

func RequestResult

func RequestResult(counter *ReadCounter, err error)

RequestResult records one actual native mutation request a statement issued: the staging call it made on its transaction, never a physical write, a final statistic or a row count derived from either. The commit decides what reaches storage, so the request's own outcome is the only fact the statement owns: a call that returned no error was acknowledged and contributes one row, and a call that failed contributes none. Either way it was one request, hence one hit.

It takes the counter rather than the context because a batch resolves its request counter once and reports every call of the loop to it; the record carries no context, name or identity of its own. A nil counter - what a statement nobody profiles resolved - reports nothing and allocates nothing.

func WithObserver

func WithObserver(ctx context.Context, observer Observer) context.Context

WithObserver binds the observer to this execution lifetime.

Types

type Observer

type Observer interface {
	// WithLifetime freezes attribution onto lifetime without retaining scope's
	// context or exposing its request values. The returned context must keep
	// lifetime's cancellation and expose the scoped observer through ObserverKey.
	WithLifetime(lifetime context.Context, scope context.Context) context.Context
	UnobservedRead(context.Context, string, string)
	// Access returns this execution's counter for the read it identifies by
	// kind and detail: the same key answers with the same counter, so every
	// reader of one read adds to one record.
	Access(context.Context, string, string) *ReadCounter
}

Observer reports a callback whose complete database access is not visible to the caller's reader observations. An observed inner read cannot certify the rest of an opaque callback.

func FromContext

func FromContext(ctx context.Context) Observer

FromContext returns this execution's observer, if the request is profiled.

type ObserverKey

type ObserverKey struct{}

ObserverKey is used only by internal context views that route request-owned metadata independently of retained statement bindings.

type ReadCounter

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

ReadCounter is the request-owned counter of one physical read: the logical rows and access units that read actually returned, and nothing derived from them.

A reader adds to the counter its observer handed it (see Access), and the profile ledger reads the values once the statement ends. The counter holds no context, no identity and no reference to the statement, so a reader that resolved it once can add from any goroutine without another observer lookup; the two atomic counters are the whole state. A counter belongs to the one record its observer keyed it under, and is used through that pointer.

func Access

func Access(ctx context.Context, kind, detail string) *ReadCounter

Access returns the counter the asking execution records a physical read of kind and detail on, or nil when the statement is not profiled. A caller adds actual logical rows and access units to the counter it gets; it must not supply estimates or count subordinate reads twice.

The counter is the observer's own record for that read, not a copy: a reader that resolves it once adds wherever it reads, without another observer lookup. Resolving it for an ordinary statement allocates nothing.

func (*ReadCounter) Add

func (c *ReadCounter) Add(rows, hits int64)

Add records rows logical rows and hits access units observed at one place. A nil counter - what Access returns for a statement nobody profiles - discards them, so an ordinary statement records nothing and allocates nothing.

func (*ReadCounter) Values

func (c *ReadCounter) Values() (rows, hits int64)

Values returns the rows and access units this counter holds. A nil counter holds none.

type ReadObservation

type ReadObservation uint8

ReadObservation is the read-observation policy a registration declares for the database access its implementation performs. It is the one policy type every callback registration shares: the Cypher function registry and the APOC callable registry both name it, and an admitted callable stores the same value.

The zero value is OpaqueReads, so a registration that doesn't state a policy is never trusted with an unobserved read.

const (
	// OpaqueReads is a callback whose complete database access is not visible
	// to the caller's reader observations: a custom implementation, a plugin
	// closure or a built-in that reads storage through a path that doesn't
	// report logical rows and access units. Every actual invocation is
	// reported through Callback, so a profile never certifies the callback's
	// complete access count from the reads observed around it.
	OpaqueReads ReadObservation = iota
	// CanonicalReads is an implementation whose reads are complete without the
	// opaque-callback hook: it either reads no database state (a pure value
	// function) or reports its own reads through the canonical observation
	// owners. Its actual invocations are not reported as opaque callbacks.
	CanonicalReads
)

func (ReadObservation) Valid

func (observation ReadObservation) Valid() bool

Valid reports whether observation names a declared policy. Every registration owner validates through this one owner, so a policy value can't mean one thing to a source registration and another to an admitted callable.

Jump to

Keyboard shortcuts

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