MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / SearchSorted

Method SearchSorted

pkg/sql/sem/tree/datum.go:3156–3169  ·  view source on GitHub ↗

SearchSorted searches the tuple for the target Datum, returning an int with the same contract as sort.Search and a boolean flag signifying whether the datum was found. It assumes that the DTuple is sorted and panics if it is not. The target Datum cannot be NULL or a DTuple that contains NULLs (we c

(ctx *EvalContext, target Datum)

Source from the content-addressed store, hash-verified

3154// binary search in this case; for example `(1, NULL) IN ((1, 2), ..)` needs to
3155// be
3156func (d *DTuple) SearchSorted(ctx *EvalContext, target Datum) (int, bool) {
3157 d.AssertSorted()
3158 if target == DNull {
3159 panic(errors.AssertionFailedf("NULL target (d: %s)", d))
3160 }
3161 if t, ok := target.(*DTuple); ok && t.ContainsNull() {
3162 panic(errors.AssertionFailedf("target containing NULLs: %#v (d: %s)", target, d))
3163 }
3164 i := sort.Search(len(d.D), func(i int) bool {
3165 return d.D[i].Compare(ctx, target) >= 0
3166 })
3167 found := i < len(d.D) && d.D[i].Compare(ctx, target) == 0
3168 return i, found
3169}
3170
3171// Normalize sorts and uniques the datum tuple.
3172func (d *DTuple) Normalize(ctx *EvalContext) {

Callers 1

makeEvalTupleInFunction · 0.80

Calls 3

AssertSortedMethod · 0.95
ContainsNullMethod · 0.80
CompareMethod · 0.65

Tested by

no test coverage detected