t11s
t11s4d ago

Is querying by indexed custom ID as fast as querying by Convex's internal _id?

In my Convex database, I have a couple tables that have a custom unique provider_id that comes from an external service I sync with. I frequently need to query by provider_id in both actions and frontend code. My question: If I create an index on provider_id, will queries using it (e.g. getting the unique document identified by provider_id) perform just as fast as queries using the internal _id? Or does Convex have special optimizations for _id that make it faster than any other indexed field?
4 Replies
Convex Bot
Convex Bot4d ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
erquhart
erquhart3d ago
Performance is identical 👍
t11s
t11sOP2d ago
nice! would be nice if there was some way to define fields as id fields so sugar like ctx.db.get() and v.id could work
erquhart
erquhart2d ago
Convex helpers has getOneOrThrow that works that way, you can import it from the convex-helpers package or just copy paste the function and get rid of the throwing behavior if you want to allow null returns: https://github.com/get-convex/convex-helpers/blob/edb15e450e79e244a0c3efbb7fdc8b66558764c0/packages/convex-helpers/server/relationships.ts#L16-L34

Did you find this page helpful?