PS-11167: Add DISTANCE() for VECTOR data type#5976
Open
catalinbp wants to merge 1 commit into
Open
Conversation
Implement SQL DISTANCE(vector, vector, metric) and the VECTOR_DISTANCE() synonym for vector similarity queries. Supported metrics: EUCLIDEAN (L2), MANHATTAN (L1), COSINE, and DOT. Core library (vector-common/vector_distance.*): - Runtime SIMD dispatch across Scalar, SSE4.2/NEON, AVX2, AVX-512F, and SVE2 tiers; per-kernel target attributes, no global -march=native - Dim-aware wide/narrow dispatch (dims >= 16 use widest tier; smaller vectors use 128-bit tier to avoid AVX setup overhead) - Unaligned load intrinsics throughout: VECTOR data may be misaligned (e.g. SUBSTR blobs); on modern CPUs unaligned and aligned loads have identical throughput when data is aligned; aligned loads would fault on misaligned inputs without a performance benefit. Loads that span a 64-byte cache-line boundary may still be slower (two line fetches); that depends on runtime address, not on loadu vs load, and is not avoided by switching to aligned intrinsics - Float32 SIMD accumulation with double-precision horizontal sum and scalar tail: preserves correctness for large dimensions and extreme values (e.g. 2e38 Euclidean distance) without sacrificing SIMD width - Manhattan (L1): sum of absolute differences;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement SQL DISTANCE(vector, vector, metric) and the VECTOR_DISTANCE() synonym for vector similarity queries. Supported metrics: EUCLIDEAN (L2), MANHATTAN (L1), COSINE, and DOT.
Core library (vector-common/vector_distance.*):