xialvjun / ts-sql-plugin

TypeScript Language Service Plugin for SQL with a tagged template strings SQL builder.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

explain cost check

darky opened this issue · comments

Would be good to have ability to setup upper bound of explain cost.
If explain cost more than this upper bound for particular query, error occured about heavy sql.
Explain cost can be set in tsconfig.json for tsserver and as cli flag for cli tool.

Example:

Limit  (cost=0.00..50000.55 rows=1000000 width=341) (actual time=0.003..0.003 rows=0 loops=1)
  ->  Seq Scan on car  (cost=0.00..12.20 rows=220 width=341) (actual time=0.002..0.002 rows=0 loops=1)
Planning Time: 0.058 ms
Execution Time: 0.015 ms

50000.55 so heavy, max upper bound is 10000

I know it, but if I add upper bound, I should add exclude too.
In fact, I should integrate ts-sql-plugin into ts-linter. But I don't know how.

Is there a directive to specify expected cost for a given query? Like this:

const myKnownExpensiveQuery = sql`
  -- @cost(50000)
  select * from expensive_view;
`;

I don't see it in the docs, but it might be nice.

Now you can use -- ts-sql-plugin:ignore-cost for ignoring cost totally

Yes, that seems very dangerous. For a high-cost query I do not want to enable it to be arbitrarily any cost – I just want to raise the allowance. That way, if the cost goes up even more, I can notice it and fix.

By the way, this is a very exciting tool, and it's very cool that you are considering cost right at the start.

#31
Will be implemented sometime