Skip to content

How to read direction predicates in iterate a cursor? #450

Closed

Description

@stelar7

for iterate a cursor there is some conditions for what is the "next" value.

* If key is defined, the record’s key is greater than or equal to key.
* If primaryKey is defined, the record’s key is equal to key and the record’s value is greater than or equal to primaryKey, or the record’s key is greater than key.
* If position is defined, and source is an object store, the record’s key is greater than position.
* If position is defined, and source is an index, the record’s key is equal to position and the record’s value is greater than object store position or the record’s key is greater than position.
* The record’s key is in range.

How are some of these conditions supposed to be read?
eg. the second one, is it like this? (same issue with the 4th one)

If primaryKey is defined:
	the record’s key is equal to key and the record’s value is greater than or equal to primaryKey, 
else:
	the record’s key is greater than key.

or like this?

If primaryKey is defined:
	(the record’s key is equal to key and the record’s value is greater than or equal to primaryKey) OR the record’s key is greater than key.

Activity

  1. inexorabletash commented on Apr 29, 2025

    @inexorabletash
    Member

    The latter. It might be clearer to format as:

    • If primaryKey is defined:
      • The record’s key is equal to key and the record’s value is greater than or equal to primaryKey.
      • The record’s key is greater than key.

    ... and similarly for the other predicates with "or" in them.

  2. SteveBeckerMSFT commented on May 1, 2025

    @SteveBeckerMSFT
    Collaborator

    For the clearer format suggested by @inexorabletash, how is OR implied between the sub-bullets?

  3. inexorabletash commented on May 1, 2025

    @inexorabletash
    Member

    It's an "AND", so to be fully explicit:

    • If primaryKey is defined, the record’s [index] key is equal to [index] key and the record’s value [primaryKey] is greater than or equal to primaryKey.
    • If primaryKey is defined, the record’s [index] key is greater than [index] key.

    Each of the bullets is a predicate that restricts the range of potential keys. Another way of saying this would be: "If there's a matching key/primaryKey, then that's the result. Otherwise it's the next in order with a matching key. If there isn't one of those it's the next in order." But it's not that simple, since if the cursor has advanced past that position then nothing should be found. Hence the current formulation.

  4. inexorabletash commented on May 2, 2025

    @inexorabletash
    Member

    Probably also worth noting: "next" is the easy case, where iterating is in natural order (that is, sorted first by the index key, the secondarily by the primary key. "nextunique" and "prev" are similarly unsurprising. "prevunique" is more complicated, because we agreed to match SQLite semantics and return the first plausible record rather than the last plausible record.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions