Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use only one SQL query for all websocket multi-queries #9375

Closed
S11001001 opened this issue Apr 9, 2021 · 1 comment
Closed

use only one SQL query for all websocket multi-queries #9375

S11001001 opened this issue Apr 9, 2021 · 1 comment
Labels
component/json-api HTTP JSON API team/ledger-clients Related to the Ledger Clients team's components.

Comments

@S11001001
Copy link
Contributor

Queries#selectContractsMultiTemplate demands that the caller do some aggregation of the matchedQueries data stored in templateId in some cases. This is represented by how trackMatchIndices sets Pos=Int in Queries, but NonEmptyList[Int] in ContractDao. Fundamentally, this is because where we use the generated predicate in SQL, we're in the WHERE context and only producing blind booleans.

We already put some effort into avoiding having to do this aggregation, so it only has to be done on multiqueries against the same template. Instead, we might shift this aggregation into the SQL generated query. There are a few ways we might do this:

  1. Somehow assign an accumulated variable from within the WHERE clause and use it in the SELECT projection clause. In other words, each successful predicate yields TRUE and also appends to a matchedQueries variable, which is then added to SELECT. I have no idea whether this makes sense.
  2. Rerun the predicates in the projection clause, summing to an array or delimited string. Basically case when (tpidn = ? and predn) then [n] else [] end where n is the index of (tpidn, predn), albeit only in the cases where the same tpid has multiple preds.
  3. union the multiple SQL queries produced in the ByInt case and aggregate the indices. Probably significantly trickier than test java codegen with strange type / module names using daml-lf directly #2.

Spun off of #9278.

@S11001001
Copy link
Contributor Author

Fixed in #10344 using approach (2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/json-api HTTP JSON API team/ledger-clients Related to the Ledger Clients team's components.
Projects
None yet
Development

No branches or pull requests

3 participants