Santhosh Balasa
Santhosh Balasa

Reputation: 184

Which searching mechanism does ANY keyword in Postgres use?

Behind the scenes how is Postgres keyword ANY is implemented ? Does it use Binary search or Sequential search ? to find the element in an array of varchars?

Eg: Some arrays can be of size 1 million

Upvotes: 0

Views: 47

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 247043

This is implemented in ExecEvalHashedScalarArrayOp in src/backend/executor/execExprInterp.c. The function comment says it all:

/*
 * Evaluate "scalar op ANY (const array)".
 *
 * Similar to ExecEvalScalarArrayOp, but optimized for faster repeat lookups
 * by building a hashtable on the first lookup.  This hashtable will be reused
 * by subsequent lookups.  Unlike ExecEvalScalarArrayOp, this version only
 * supports OR semantics.
 *
 * Source array is in our result area, scalar arg is already evaluated into
 * fcinfo->args[0].
 *
 * The operator always yields boolean.
 */

Use the source, Luke!

Upvotes: 1

Related Questions