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
Secondary indexes doc has outdated information #731
This is no longer true. We've implemented r.minval/r.maxval, as well as openness and closeness in between. The doc should be updated (see rethinkdb/rethinkdb#955 for how users can use between to query compound indexes by prefix).
Also, r.minval and r.maxval should probably be listed somewhere in the main API documentation - right now they're only tucked away in the long-form docs for between, IIRC.
r.minval/maxval also don't show up in the data explorer suggestions (since they aren't documented as separate terms). I agree that we should document them as part of this issue.
Are r.minval and r.maxval still for use only within between, or can they be serialized? I was trying to figure out how I'd sink documents for a secondary index I skim the top of, and it seemed like a good case for using r.maxval or Infinity - or is it possible to just allow those documents to opt out of the index altogether with a value like null?
I can post in more detail in the Google group, but what I'm trying to indicate, regarding the subject of this issue, is that it isn't clear from the current secondary index / getAll docs how to represent, query (or avoid querying), and/or join with missing or partial indices, or if such cases are even valid.
(Edit: rethinkdb/rethinkdb#1032 makes the situation around missing / null value indices significantly clearer.)
It's especially confusing regarding the relationship between rethinkdb/rethinkdb#955 and rethinkdb/rethinkdb#1032, which is also listed as a "limitation" that seems like it gives desirable behavior. (And what does not indexing null values mean in the context of compound indices?)
Regarding my question about omitting documents from a secondary index, using null is/was a way to do that, but there's movement toward making null a discrete value (with a place in sorting) for secondary indices - rethinkdb/rethinkdb#1032 (comment) seems to imply the way forward for excluding docs from a secondary index is to use a complex expression that will generate an error for these cases (which strikes me as a little weird, if for no other reason than that when I think "error", I think "anomalous operation that gets flagged and logged and might halt the caller", not "normal result value").
Also, while we're on the subject of issues with the sindex documentation, rethinkdb/rethinkdb#2773 should be mentioned in the same breath as rethinkdb/rethinkdb#1032 for the paragraph on how secondary indices can't be null or objects.
for jar7, will this join just join jar, or will it join jar and baz?
It will join nothing for jar7 because the join function errors on that document and so it cannot determine its join key.
For a similar reason, jar can actually never be joined with anything because it will not appear in the secondary index since the secondary index function cannot be evaluated on it. You have to use default in the secondary index function if you want to handle missing fields and index those documents in a different way instead.
@stuartpb For clarification: There's nothing special about compound indexes in RethinkDB. They are simply indexes with arrays as keys. You can also have a "mixed" index where some values are indexed under arrays and others are not.
Would that work now, or does rethinkdb/rethinkdb#1032 need to be implemented? What about if the defaults were '' instead of null? What about r.branch(r.row.hasFields('commentId'),[r.row("articleId"), r.row("commentId")], [r.row("articleId")]) and its counterpart?
@stuartpb you can deduce the behavior of the query under those functions as follows:
The document jar in the posts table will now be indexed under this value: ['abc123', null]
During the join, the document jar7 from the watchers table will lead to a lookup of the key ['abc123', null]. eq_join does an equality lookup, so it will match exactly the document jar and none of the others, since ['abc123', null] = ['abc123', null] but not for example ['abc123', null] = ['abc123', specificco]. There really is no magic to this. Arrays are equal if they are the same length and all of their elements are equal. null is just a value like any other, and since it's inside of an array here it isn't affected by Disallow getting changes on a filtered limit #1032. Incidentally, that is why we want to fix Disallow getting changes on a filtered limit #1032, since secondary indexes currently break that rule by making null special which is bad and confusing.
This error behavior is something I feel the docs kind of gloss over right now: the JavaScript (and Lua) programmer in me translates [r.row('foo'), r.row('bar')] to [row.foo, row.bar] which would evaluate to something like ['value', undefined], which has equivalent access semantics to ['value'] (although the length of the former, in JS, is still 2). So what I intuitively "expect" is somewhat muddled, but the idea that getting a missing field will result in an error, which causes the expression to fail and (silently) omit the row from the index (as we're currently discussing in rethinkdb/rethinkdb#1032), is not what I would predict (for all I would guess, these errors would get triggered on insertion and get forwarded back to my client as a failed transaction).
I'd say this error behavior should be described up-front in the docs on secondary indices, ie. with a mention in the examples for complex (expression-based) indexes, and then a whole section describing how errors get handled in index creation (with links to issues like rethinkdb/rethinkdb#4118) and how that may or may not be what you want (link to rethinkdb/rethinkdb#4121).
On the subject of compound indexes: are you saying there's nothing special about compound indexes, in terms of how they're implemented and what perf characteristics they have, versus any other ReQL expression (except that more complex ReQL expressions may take longer to evaluate by virtue of being more complex)?
If so, I'd say they shouldn't have their own heading in the secondary index docs - at least, not where they are right now, where they come between simple indexes and multi indexes (and separate from the section on expressions). They should be listed as an example of "a common case of defining an index by an expression", possibly as the lead-in into the section on more complicated expressions.
The notion of array equivalence (when an index is not defined as multi) should probably be raised as an example within the section on simple indexes, as this is another feature that can be counter-intuitive, if starting from a language-semantics (JavaScript) mindset (where ['a','b','c'] != ['a','b','c']). I think this would work well near the end of the section, acting as a lead-in to the contrasting multi behavior (so, kind of like it is now, except using a field with array values rather than a ReQL expression, so as to provide a gentler learning curve for the later section on expression-based indexes).
Also, from what I've gleaned from the docs and this discussion, I can't answer the question of which index expression I'd be better off using, the default-null-for-missing-fields version or the branch-to-use-different-length-arrays version. Is one going to have significantly better perf characteristics?
I'd say this error behavior should be described up-front in the docs on secondary indices, ie. with a mention in the examples for complex (expression-based) indexes,
I think we should still mention compound indexes explicitly. Most people think of them as a separate use case, and in most other databases they are completely separate index types. It so happens that RethinkDB's regular indexes are powerful enough to cover this use case too, but we should still explain exactly how to accomplish it.
It sounds like a good idea to point out that compound indexes in RethinkDB are merely indexes over an array composed of multiple fields, and are hence just a special instance of regular indexes. We should do that (@chipotle).
I can't answer the question of which index expression I'd be better off using, the default-null-for-missing-fields version or the branch-to-use-different-length-arrays version. Is one going to have significantly better perf characteristics?
Their performance will be similar, but they'll sort differently. An array [X] will sort below [X, y] for any y, but [X, null] will sort equal to [X, null] and below and/or above some other values of y in [X, y].
Just opened #734 for documenting that part.
I'd say this error behavior should be described up-front in the docs on secondary indices, ie. with a mention in the examples for complex (expression-based) indexes
I've been digging through this and I confess I've gotten a bit lost. What error behavior are we talking about documenting? The suggestion to use r.error as the official way of deliberately omitting documents from secondary indexes?
The fact that errors cause documents to not be indexed, and do not get reported or fail the query.
On Apr 30, 2015 11:30 AM, Watts [email protected] wrote:
I'd say this error behavior should be described up-front in the docs on secondary indices, ie. with a mention in the examples for complex (expression-based) indexes
I've been digging through this and I confess I've gotten a bit lost. What error behavior are we talking about documenting? The suggestion to use r.error as the official way of deliberately omitting documents from secondary indexes?
—Reply to this email directly or view it on GitHub.
Activity
stuartpb commentedon Apr 24, 2015
Also, r.minval and r.maxval should probably be listed somewhere in the main API documentation - right now they're only tucked away in the long-form docs for
between, IIRC.coffeemug commentedon Apr 24, 2015
r.minval/maxvalalso don't show up in the data explorer suggestions (since they aren't documented as separate terms). I agree that we should document them as part of this issue.stuartpb commentedon Apr 24, 2015
Are r.minval and r.maxval still for use only within
between, or can they be serialized? I was trying to figure out how I'd sink documents for a secondary index I skim the top of, and it seemed like a good case for using r.maxval or Infinity - or is it possible to just allow those documents to opt out of the index altogether with a value likenull?coffeemug commentedon Apr 24, 2015
minval/maxvalaren't serializable.I'm not entirely sure what you're trying to do. Could you post on https://groups.google.com/forum/#!forum/rethinkdb and we'll help figure it out?
stuartpb commentedon Apr 24, 2015
I can post in more detail in the Google group, but what I'm trying to indicate, regarding the subject of this issue, is that it isn't clear from the current secondary index / getAll docs how to represent, query (or avoid querying), and/or join with
missing orpartial indices, or if such cases are even valid.(Edit: rethinkdb/rethinkdb#1032 makes the situation around missing / null value indices significantly clearer.)
For instance, if I have a table where I have done
r.table('posts').indexCreate("location", [r.row("articleId"), r.row("commentId")])And then I push a few documents, including a document with an
articleIdbut nocommentId(ie. because it refers to the "article" itself):and then I have a few more documents in another table ('watchers'), including one that refers to the no-comment object
jar:And then I run a
joinon this compound index:r.table('watchers').join([r.row('foreignArticleId'),r.row('foreignCommentId')],'posts',{index:'location'})for
jar7, will this join just joinjar, or will it joinjarandbaz?stuartpb commentedon Apr 24, 2015
It's especially confusing regarding the relationship between rethinkdb/rethinkdb#955 and rethinkdb/rethinkdb#1032, which is also listed as a "limitation" that seems like it gives desirable behavior. (And what does not indexing null values mean in the context of compound indices?)
stuartpb commentedon Apr 24, 2015
Regarding my question about omitting documents from a secondary index, using null is/was a way to do that, but there's movement toward making
nulla discrete value (with a place in sorting) for secondary indices - rethinkdb/rethinkdb#1032 (comment) seems to imply the way forward for excluding docs from a secondary index is to use a complex expression that will generate an error for these cases (which strikes me as a little weird, if for no other reason than that when I think "error", I think "anomalous operation that gets flagged and logged and might halt the caller", not "normal result value").stuartpb commentedon Apr 24, 2015
Also, while we're on the subject of issues with the sindex documentation, rethinkdb/rethinkdb#2773 should be mentioned in the same breath as rethinkdb/rethinkdb#1032 for the paragraph on how secondary indices can't be null or objects.
danielmewes commentedon Apr 24, 2015
@stuartpb
It will join nothing for
jar7because the join function errors on that document and so it cannot determine its join key.For a similar reason,
jarcan actually never be joined with anything because it will not appear in the secondary index since the secondary index function cannot be evaluated on it. You have to usedefaultin the secondary index function if you want to handle missing fields and index those documents in a different way instead.danielmewes commentedon Apr 24, 2015
@stuartpb For clarification: There's nothing special about compound indexes in RethinkDB. They are simply indexes with arrays as keys. You can also have a "mixed" index where some values are indexed under arrays and others are not.
stuartpb commentedon Apr 24, 2015
What if the code were changed to
r.table('posts').indexCreate("location", [r.row("articleId").default(null), r.row("commentId").default(null)])and
r.table('watchers').join([r.row('foreignArticleId').default(null),r.row('foreignCommentId').default(null)],'posts',{index:'location'})Would that work now, or does rethinkdb/rethinkdb#1032 need to be implemented? What about if the defaults were
''instead ofnull? What aboutr.branch(r.row.hasFields('commentId'),[r.row("articleId"), r.row("commentId")], [r.row("articleId")])and its counterpart?danielmewes commentedon Apr 24, 2015
@stuartpb you can deduce the behavior of the query under those functions as follows:
jarin thepoststable will now be indexed under this value:['abc123', null]jar7from thewatcherstable will lead to a lookup of the key['abc123', null].eq_joindoes an equality lookup, so it will match exactly the documentjarand none of the others, since['abc123', null] = ['abc123', null]but not for example['abc123', null] = ['abc123', specificco]. There really is no magic to this. Arrays are equal if they are the same length and all of their elements are equal.nullis just a value like any other, and since it's inside of an array here it isn't affected by Disallow getting changes on a filtered limit #1032. Incidentally, that is why we want to fix Disallow getting changes on a filtered limit #1032, since secondary indexes currently break that rule by makingnullspecial which is bad and confusing.stuartpb commentedon Apr 24, 2015
This error behavior is something I feel the docs kind of gloss over right now: the JavaScript (and Lua) programmer in me translates
[r.row('foo'), r.row('bar')]to[row.foo, row.bar]which would evaluate to something like['value', undefined], which has equivalent access semantics to['value'](although thelengthof the former, in JS, is still 2). So what I intuitively "expect" is somewhat muddled, but the idea that getting a missing field will result in an error, which causes the expression to fail and (silently) omit the row from the index (as we're currently discussing in rethinkdb/rethinkdb#1032), is not what I would predict (for all I would guess, these errors would get triggered on insertion and get forwarded back to my client as a failed transaction).I'd say this error behavior should be described up-front in the docs on secondary indices, ie. with a mention in the examples for complex (expression-based) indexes, and then a whole section describing how errors get handled in index creation (with links to issues like rethinkdb/rethinkdb#4118) and how that may or may not be what you want (link to rethinkdb/rethinkdb#4121).
stuartpb commentedon Apr 24, 2015
On the subject of compound indexes: are you saying there's nothing special about compound indexes, in terms of how they're implemented and what perf characteristics they have, versus any other ReQL expression (except that more complex ReQL expressions may take longer to evaluate by virtue of being more complex)?
If so, I'd say they shouldn't have their own heading in the secondary index docs - at least, not where they are right now, where they come between simple indexes and multi indexes (and separate from the section on expressions). They should be listed as an example of "a common case of defining an index by an expression", possibly as the lead-in into the section on more complicated expressions.
The notion of array equivalence (when an index is not defined as
multi) should probably be raised as an example within the section on simple indexes, as this is another feature that can be counter-intuitive, if starting from a language-semantics (JavaScript) mindset (where['a','b','c'] != ['a','b','c']). I think this would work well near the end of the section, acting as a lead-in to the contrastingmultibehavior (so, kind of like it is now, except using a field with array values rather than a ReQL expression, so as to provide a gentler learning curve for the later section on expression-based indexes).Also, from what I've gleaned from the docs and this discussion, I can't answer the question of which index expression I'd be better off using, the default-null-for-missing-fields version or the branch-to-use-different-length-arrays version. Is one going to have significantly better perf characteristics?
danielmewes commentedon Apr 24, 2015
That's a great idea. (@chipotle)
I think we should still mention compound indexes explicitly. Most people think of them as a separate use case, and in most other databases they are completely separate index types. It so happens that RethinkDB's regular indexes are powerful enough to cover this use case too, but we should still explain exactly how to accomplish it.
It sounds like a good idea to point out that compound indexes in RethinkDB are merely indexes over an array composed of multiple fields, and are hence just a special instance of regular indexes. We should do that (@chipotle).
Their performance will be similar, but they'll sort differently. An array
[X]will sort below[X, y]for anyy, but[X, null]will sort equal to[X, null]and below and/or above some other values ofyin[X, y].Just opened #734 for documenting that part.
chipotle commentedon Apr 30, 2015
I've been digging through this and I confess I've gotten a bit lost. What error behavior are we talking about documenting? The suggestion to use
r.erroras the official way of deliberately omitting documents from secondary indexes?stuartpb commentedon Apr 30, 2015
The fact that errors cause documents to not be indexed, and do not get reported or fail the query.
On Apr 30, 2015 11:30 AM, Watts [email protected] wrote:
I'd say this error behavior should be described up-front in the docs on secondary indices, ie. with a mention in the examples for complex (expression-based) indexes
I've been digging through this and I confess I've gotten a bit lost. What error behavior are we talking about documenting? The suggestion to use r.error as the official way of deliberately omitting documents from secondary indexes?
—Reply to this email directly or view it on GitHub.