You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Don't index this row" value for secondary indexes #4121
As suggested in #1032 (comment) and the next ~7 replies after it, this would be a way of providing a value to skip indexing a row for index expressions, rather than just relying on errors or the (soon to be changed) unindexed behavior of null.
Another reason I think the value for this should be undefined/r.absent is because it would make the behavior of simple indexes in the absence of a field that much more predictable/straightforward to reason about. (absent being a suggestion from #1032 (comment))
Also, absent makes sense for use in querying as well, both for getting the set of all rows that do not have a value for an index (like #1032 (comment) described for null back when null had the semantics of this proposed value), or for (possibly future use) more complex query/filter expressions where all documents that do have a field should be excluded (could be inverted and rewritten to not(hasFields()) by the driver or implementation).
This is a very interesting idea to me. It seems to me that a value of r.absent might also serve to remove a key from a record: .update({foo: r.absent}) instead of .replace(r.row.without('foo'))? If this were the case, such a value would have to be distinct from the language's concept of undefined.
PostgreSQL allows a CREATE INDEX name ON table WHERE predictate, could we do something similar with a function returning a boolean indicating whether or not to include a row in the index?
@VeXocide I think we would probably not have a separate function, but have it part of the index function. Unless there's a good reason for having it separate.
You can already do this with something like function (x) { return r.branch(predicate(x), x('field'), null) }
With this proposal that would become function (x) { return r.branch(predicate(x), x('field'), r.absent) }
I think that's nicer than a second function because it's more generic and doesn't add another argument to indexCreate. I might be wrong of course.
Activity
danielmewes commentedon Apr 24, 2015
Thanks for opening a separate issue. We'll discuss and schedule this together with #1032 once we have the time.
stuartpb commentedon Apr 24, 2015
Another reason I think the value for this should be
undefined/r.absentis because it would make the behavior of simple indexes in the absence of a field that much more predictable/straightforward to reason about. (absentbeing a suggestion from #1032 (comment))Also,
absentmakes sense for use in querying as well, both for getting the set of all rows that do not have a value for an index (like #1032 (comment) described fornullback whennullhad the semantics of this proposed value), or for (possibly future use) more complex query/filter expressions where all documents that do have a field should be excluded (could be inverted and rewritten tonot(hasFields())by the driver or implementation).mike-marcacci commentedon May 8, 2015
This is a very interesting idea to me. It seems to me that a value of
r.absentmight also serve to remove a key from a record:.update({foo: r.absent})instead of.replace(r.row.without('foo'))? If this were the case, such a value would have to be distinct from the language's concept ofundefined.AtnNn commentedon May 8, 2015
An empty
r.literalalready does this:VeXocide commentedon May 8, 2015
PostgreSQL allows a
CREATE INDEX name ON table WHERE predictate, could we do something similar with a function returning a boolean indicating whether or not to include a row in the index?mike-marcacci commentedon May 8, 2015
Wow, I had never used
r.literal()without a value (usually a nested objected with some omitted keys)... I learn something new every time I comment! :)danielmewes commentedon May 8, 2015
@VeXocide I think we would probably not have a separate function, but have it part of the index function. Unless there's a good reason for having it separate.
You can already do this with something like
function (x) { return r.branch(predicate(x), x('field'), null) }With this proposal that would become
function (x) { return r.branch(predicate(x), x('field'), r.absent) }I think that's nicer than a second function because it's more generic and doesn't add another argument to
indexCreate. I might be wrong of course.VeXocide commentedon May 8, 2015
@danielmewes -- I agree
r.absentis nicer here, you can ignore my previous proposal.