Skip to content

Add "strict" mode for indices #5967

Open

Description

@mike-marcacci

I wrote this as a comment to #1032 and immediately realized it should be its own issue.


I'd like to add to this proposal. As far as I currently understand, the plan is to:

  • start indexing null values
  • ignore rows that return an "undefined" type using r.absent() or the existing r.literal()

I'd like to also reconsider the behavior of an r.error() (or an implicit error, like operating on the wrong type or not specifying a default) when returned by an index function. I'd propose that a write operation fail if any index returns an error. Likewise, I would propose that creating an index should fail if any documents return such an error.

This would ensure our indices are expecting the correct document structures, and aren't silently missing documents that we would expect to have indexed. This would also have the effect of validating every document in the table.

To ensure backwards-compatibility and ease the process of schema migrations, indexCreate could receive a boolean option of strict to enable this behavior.

Piggy-backing on the same logic, rethinkdb could introduce the concept of "validators" which would function similarly to "strict" indices, but wouldn't actually create the b-trees. This could essentially accomplish #5494, #5879, and #4210, as any json-schema or Joi schema could be compiled into a rql expression and stored as a "validator" expression in the database.

Activity

  1. danielmewes commented on Jul 19, 2016

    @danielmewes
    Member

    I like the idea, and I think it can be done with a bit of refactoring in our code.
    I think we should keep our current behavior as the default (to stay with the philosophy of a schemaless DB), but allow strict index behavior to be enabled via an option as you say.

    I think validators are a bit separate, as they aren't really related to indexes per se. (also note that #5813 which is going to ship with 2.4 allows you to implement validators)

  2. added this to the subsequent milestone on Jul 19, 2016
  3. mike-marcacci commented on Jul 19, 2016

    @mike-marcacci
    Author

    @danielmewes thanks for the reply! I totally agree about keeping the current behavior as default, and about my "validators" extrapolation already being covered by #5813 – which I had somehow totally missed! What an awesome proposal!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions