graphile / issues

Issue management for supporter/pro plugins, etc
1 stars 0 forks source link

Introduce smart comments to allow hinting at the cost of an unlimited query of a table #4

Closed deinspanjer closed 4 years ago

deinspanjer commented 5 years ago

If we could put a comment on a table or a foreign key constraint that would hint to the cost calculator what estimate it should use as the number of rows to be returned when a limit isn't specified in the query, it would allow the schema developer to provide a more streamlined experience to their users.

Having the ability to force users to specify a limit on very big tables works great, however, if you know the table is small and it won't return a lot of rows, then forcing the user to still specify a limit makes for a slightly clunkier experience for them. If we don't force them, then the calculated cost for the query is 1000 which is likely too high since we didn't force limits since we know there aren't that many rows to be returned.

At a minimum level, having the following comment would help:

maxRowEstimate -- Tells the calculator how many rows the dev expects would be returned if the user did not specify a limit. Can be put on a table, or on a foreign key constraint. If the relation is being hit via a link in the graph, the constraint value would take precedence, and if it isn't specified, fall back to the table value.

I imagine we could probably get fancier and try to tap into the pg stats, but while that would be fun, it would probably be a lot more complicated to figure out.

benjie commented 4 years ago

Sorry for the delay on this, it slipped off my radar. v0.9.0 adds support for this via tables and functions ─ see https://www.npmjs.com/package/@graphile/pro#unboundedallcost-default-100000

Unfortunately I couldn't add it to the foreign key constraints because graphile-build-pg doesn't expose the necessary fields there yet. If you need this, let me know and I'll raise the relevant issue.