graphile / crystal

🔮 Graphile's Crystal Monorepo; home to Grafast, PostGraphile, pg-introspection, pg-sql2 and much more!
https://graphile.org/
Other
12.63k stars 572 forks source link

Is it possible to do subquery LIMIT via GraphQL #349

Closed rentrop closed 6 years ago

rentrop commented 7 years ago

In the postgres doku on Controlling Text Search the last example explains how to use ts_headline as follows:

SELECT id, ts_headline(body, q), rank
FROM (SELECT id, body, q, ts_rank_cd(ti, q) AS rank
      FROM apod, to_tsquery('stars') q
      WHERE ti @@ q
      ORDER BY rank DESC
      LIMIT 10) AS foo;

Is it possible to do this LIMIT 10 aka first: 10 in postgraphql? In the doku they point out that ts_headline is slow as its working on the original body instead of the ts_vector ti. Thats why they advice to use ts_headline only on a limited result-set.

So far i have implemented postgres FTS via a stable postges procedure as described in advanced queries. It would be great to "past-process" a limited query.

benjie commented 7 years ago

You can add additional arguments to your function that apply the limit; if you return a set then you can't name them first but you could do rowLimit or similar?

rentrop commented 7 years ago

Year that is true. But then you also have to to the pagination yourself, right?

calebmer commented 7 years ago

Interesting, yeah, you’d be limited to only paginating rowLimit rows, right?

Three questions:

  1. Is there a way to flatten the query? I guess not, right, because ts_headline would then run on everything. See if explain analyze has any insight on this as it may be optimized.
  2. If the limit is removed does Postgres optimize with the limit PostGraphQL provides?
  3. Is there a reason you can’t use a ts_vector?
benjie commented 6 years ago

[semi-automated message] Hi, there has been no activity in this issue for over 8 weeks so I'm closing it to keep the issues/pull request manageable. If this is still an issue, please re-open with a comment explaining why.