Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
only binary collation in row group elimination
Browse files Browse the repository at this point in the history
  • Loading branch information
dgllghr committed Mar 7, 2024
1 parent 7950192 commit 8611236
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/index/sort_key.zig
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ fn chooseConstraintBounds(
if (!constraint.usable()) {
continue;
}
// Row group elimination only supports binary collation, so disqualify the constraint if
// a different collation is required
// TODO .rtrim may be useful for row group elimination
if (constraint.collation() != .binary) {
continue;
}

const col_index = constraint.columnIndex();
const sk_index = mem.indexOfScalar(usize, sort_key_columns, @intCast(col_index));
Expand Down
26 changes: 26 additions & 0 deletions src/sqlite3/vtab.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! This is inspired by [zig-sqlite](https://github.com/vrischmann/zig-sqlite)

const std = @import("std");
const ascii = std.ascii;
const debug = std.debug;
const fmt = std.fmt;
const heap = std.heap;
Expand Down Expand Up @@ -114,6 +115,25 @@ const ArenaPool = struct {
}
};

pub const CollationSequence = enum {
binary,
nocase,
rtrim,

pub fn fromName(name: [:0]const u8) ?CollationSequence {
if (ascii.eqlIgnoreCase("BINARY", name)) {
return .binary;
}
if (ascii.eqlIgnoreCase("NOCASE", name)) {
return .nocase;
}
if (ascii.eqlIgnoreCase("RTRIM", name)) {
return .rtrim;
}
return null;
}
};

pub const BestIndexInfo = struct {
index_info: ?*c.sqlite3_index_info,

Expand Down Expand Up @@ -196,6 +216,12 @@ pub const BestIndexInfo = struct {
) !void {
try writer.print("{} col {}", .{ self.op(), self.columnIndex() });
}

/// Returns null if the collation sequence is not one of the standard 3 collation sequences
pub fn collation(self: Constraint) ?CollationSequence {
const name = c.sqlite3_vtab_collation(self.parent.?, @intCast(self.index));
return CollationSequence.fromName(mem.span(name));
}
};

pub fn constraintsLen(self: BestIndexInfo) u32 {
Expand Down

0 comments on commit 8611236

Please sign in to comment.