Skip to content

sql: rewrite index constraint / span generation #6346

@RaduBerinde

Description

@RaduBerinde

The span generation code (in index selection) is very complicated and makes it hard to add new features (e.g. see #6206).

The code generates indexConstraints which store parts of expressions and those later get converted to spans. Ideas for how to change things:

  • Instead of generating key spans (which makes the code somewhat intertwined with the particulars of how we map tables to KVs), we should represent spans in a KV-agnostic way. The span start and end can each be a list of values (for a prefix of the index columns) plus an inclusive-vs-exclusive flag.

    This is related to distributed SQL as well: the wire protocol should be agnostic to how we encode indexes into KVs; passing spans over the wire using lists of values is preferable.

  • Instead of indexConstraints storing pieces of expressions and tuple maps, they would store begin and end values with inclusive-vs-exclusive flags

  • We already have an algorithm implemented for merging overlapping spans which we can leverage to simplify the code and make it more powerful (the current code makes sure the indexConstraints don't overlap inside each disjunction).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions