ian
ian•3y ago

ordering when using an index vs. without an index

useQuery will return undefined until it gets the first response, but shouldn't return it after that. I'm guessing you're talking about db.query...collect() returning undefined? If you see it again, holler!
5 Replies
RJ
RJ•3y ago
I was talking about the db.query...collect(), and I'm actually able to reproduce it if I revert my schema indexes back to what I had yesterday. Give me a moment and I'll share more details I was mistaken; looks like it's an ordering issue: steps1 result
[{
_creationTime: 1666200098547.0938,
_id: Id('steps', 'IL7m9oNPNUKEg2aIzFFhsgm'),
clientId: 'f6fbb396-a45e-4ab7-b331-4047da447aa3',
docId: Id('docs', 'X5vJ3yQ1NgeSr1SUNQZbQ1g'),
position: 2208,
step: '{"stepType":"replace","from":92,"to":92,"slice":{"content":[{"type":"text","text":"f"}]}}'
}, {
_creationTime: 1666200098547.0942,
_id: Id('steps', 'MdLLc62YPRLfQXXXNV99JQy'),
clientId: 'f6fbb396-a45e-4ab7-b331-4047da447aa3',
docId: Id('docs', 'X5vJ3yQ1NgeSr1SUNQZbQ1g'),
position: 2210,
step: '{"stepType":"replace","from":94,"to":94,"slice":{"content":[{"type":"text","text":"f"}]}}'
}, {
_creationTime: 1666200098547.094,
_id: Id('steps', 'wRqMxe9JBaf0LfJRVWY6G811'),
clientId: 'f6fbb396-a45e-4ab7-b331-4047da447aa3',
docId: Id('docs', 'X5vJ3yQ1NgeSr1SUNQZbQ1g'),
position: 2209,
step: '{"stepType":"replace","from":93,"to":93,"slice":{"content":[{"type":"text","text":"d"}]}}'
}]
[{
_creationTime: 1666200098547.0938,
_id: Id('steps', 'IL7m9oNPNUKEg2aIzFFhsgm'),
clientId: 'f6fbb396-a45e-4ab7-b331-4047da447aa3',
docId: Id('docs', 'X5vJ3yQ1NgeSr1SUNQZbQ1g'),
position: 2208,
step: '{"stepType":"replace","from":92,"to":92,"slice":{"content":[{"type":"text","text":"f"}]}}'
}, {
_creationTime: 1666200098547.0942,
_id: Id('steps', 'MdLLc62YPRLfQXXXNV99JQy'),
clientId: 'f6fbb396-a45e-4ab7-b331-4047da447aa3',
docId: Id('docs', 'X5vJ3yQ1NgeSr1SUNQZbQ1g'),
position: 2210,
step: '{"stepType":"replace","from":94,"to":94,"slice":{"content":[{"type":"text","text":"f"}]}}'
}, {
_creationTime: 1666200098547.094,
_id: Id('steps', 'wRqMxe9JBaf0LfJRVWY6G811'),
clientId: 'f6fbb396-a45e-4ab7-b331-4047da447aa3',
docId: Id('docs', 'X5vJ3yQ1NgeSr1SUNQZbQ1g'),
position: 2209,
step: '{"stepType":"replace","from":93,"to":93,"slice":{"content":[{"type":"text","text":"d"}]}}'
}]
steps2 result:
[{
_creationTime: 1666200098547.0938,
_id: Id('steps', 'IL7m9oNPNUKEg2aIzFFhsgm'),
clientId: 'f6fbb396-a45e-4ab7-b331-4047da447aa3',
docId: Id('docs', 'X5vJ3yQ1NgeSr1SUNQZbQ1g'),
position: 2208,
step: '{"stepType":"replace","from":92,"to":92,"slice":{"content":[{"type":"text","text":"f"}]}}'
}, {
_creationTime: 1666200098547.094,
_id: Id('steps', 'wRqMxe9JBaf0LfJRVWY6G811'),
clientId: 'f6fbb396-a45e-4ab7-b331-4047da447aa3',
docId: Id('docs', 'X5vJ3yQ1NgeSr1SUNQZbQ1g'),
position: 2209,
step: '{"stepType":"replace","from":93,"to":93,"slice":{"content":[{"type":"text","text":"d"}]}}'
}, {
_creationTime: 1666200098547.0942,
_id: Id('steps', 'MdLLc62YPRLfQXXXNV99JQy'),
clientId: 'f6fbb396-a45e-4ab7-b331-4047da447aa3',
docId: Id('docs', 'X5vJ3yQ1NgeSr1SUNQZbQ1g'),
position: 2210,
step: '{"stepType":"replace","from":94,"to":94,"slice":{"content":[{"type":"text","text":"f"}]}}'
}]
[{
_creationTime: 1666200098547.0938,
_id: Id('steps', 'IL7m9oNPNUKEg2aIzFFhsgm'),
clientId: 'f6fbb396-a45e-4ab7-b331-4047da447aa3',
docId: Id('docs', 'X5vJ3yQ1NgeSr1SUNQZbQ1g'),
position: 2208,
step: '{"stepType":"replace","from":92,"to":92,"slice":{"content":[{"type":"text","text":"f"}]}}'
}, {
_creationTime: 1666200098547.094,
_id: Id('steps', 'wRqMxe9JBaf0LfJRVWY6G811'),
clientId: 'f6fbb396-a45e-4ab7-b331-4047da447aa3',
docId: Id('docs', 'X5vJ3yQ1NgeSr1SUNQZbQ1g'),
position: 2209,
step: '{"stepType":"replace","from":93,"to":93,"slice":{"content":[{"type":"text","text":"d"}]}}'
}, {
_creationTime: 1666200098547.0942,
_id: Id('steps', 'MdLLc62YPRLfQXXXNV99JQy'),
clientId: 'f6fbb396-a45e-4ab7-b331-4047da447aa3',
docId: Id('docs', 'X5vJ3yQ1NgeSr1SUNQZbQ1g'),
position: 2210,
step: '{"stepType":"replace","from":94,"to":94,"slice":{"content":[{"type":"text","text":"f"}]}}'
}]
Now is that actually incorrect behavior? 😛 Does
If not specified, the order defaults to ascending.
in https://docs.convex.dev/api/interfaces/server.Query#order mean that if an ordering is not specified with order(), the order will be ascending? Or that you can call order() without arguments to have the result be ordered ascending?
ian
ianOP•3y ago
That will be fixed soon. Without an index, we have a default ordering of _creationTime. If you use an index, we used to still have a default ordering of _id so your steps1 result is ordered by _id and the latter is ordered by _creationTime @presley changed this recently. We're glad the change is making it less confusing 🙂
RJ
RJ•3y ago
Is that what
Results will be returned in index order.
in https://docs.convex.dev/api/interfaces/server.QueryInitializer#withindex meant/means?
ian
ianOP•3y ago
Right. I'm going to be fixing up those docs to reference the new _creationTime default ordering. Very open to feedback on it
RJ
RJ•3y ago
Got it, great! Yes, as it stands it's confusing, but the change you say is coming is exactly what I would have assumed, based on the docs as they're written now (excepting what's in withIndex)

Did you find this page helpful?