Skip to content

Commit

Permalink
Use a combined template id, stakeholder index
Browse files Browse the repository at this point in the history
fixes #10231

Before

Benchmark (batchSize) (extraParties) (extraTemplates) Mode Cnt Score Error Units
QueryBenchmark.run 10000 0 1 avgt 5 0.277 ± 0.037 s/op
QueryBenchmark.run 10000 0 10 avgt 5 0.479 ± 0.301 s/op
QueryBenchmark.run 10000 0 100 avgt 5 2.131 ± 0.497 s/op

After

Benchmark           (batchSize)  (extraParties)  (extraTemplates)  Mode  Cnt  Score   Error  Units
QueryBenchmark.run        10000               1                 0  avgt    5  0.274 ± 0.141   s/op
QueryBenchmark.run        10000              10                 0  avgt    5  0.299 ± 0.144   s/op
QueryBenchmark.run        10000             100                 0  avgt    5  0.281 ± 0.038   s/op

changelog_begin
changelog_end
  • Loading branch information
cocreature committed Jul 19, 2021
1 parent 5382253 commit d26d36e
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ sealed abstract class Queries {

protected[this] def contractsTableSignatoriesObservers: Fragment

private[this] val indexContractsTable = CreateIndex(sql"""
CREATE INDEX contract_tpid_idx ON contract (tpid)
""")

private[this] val createOffsetTable = CreateTable(
"ledger_offset",
sql"""
Expand Down Expand Up @@ -110,7 +106,6 @@ sealed abstract class Queries {
createTemplateIdsTable,
createOffsetTable,
createContractsTable,
indexContractsTable,
)

private[http] def initDatabase(implicit log: LogHandler): ConnectionIO[Unit] = {
Expand Down Expand Up @@ -478,7 +473,12 @@ private object PostgresQueries extends Queries {
CREATE INDEX contract_tpid_key_idx ON contract USING BTREE (tpid, key)
""")

protected[this] override def initDatabaseDdls = super.initDatabaseDdls :+ indexContractsKeys
private[this] val indexContractsTable = CreateIndex(sql"""
CREATE INDEX contract_tpid_idx ON contract (tpid)
""")

protected[this] override def initDatabaseDdls =
super.initDatabaseDdls :+ indexContractsTable :+ indexContractsKeys

protected[this] override def contractsTableSignatoriesObservers = sql"""
,signatories TEXT ARRAY NOT NULL
Expand Down Expand Up @@ -631,13 +631,13 @@ private object OracleQueries extends Queries {
"contract_stakeholders",
sql"""CREATE MATERIALIZED VIEW contract_stakeholders
BUILD IMMEDIATE REFRESH FAST ON STATEMENT AS
SELECT contract_id, stakeholder FROM contract,
SELECT contract_id, tpid, stakeholder FROM contract,
json_table(json_array(signatories, observers), '$$[*][*]'
columns (stakeholder $partyType path '$$'))""",
)

private[this] def stakeholdersIndex = CreateIndex(
sql"""CREATE INDEX stakeholder_idx ON contract_stakeholders (stakeholder)"""
sql"""CREATE INDEX stakeholder_idx ON contract_stakeholders (tpid, stakeholder)"""
)

protected[this] override def initDatabaseDdls =
Expand Down Expand Up @@ -684,7 +684,7 @@ private object OracleQueries extends Queries {
case q +-: qs =>
joinFragment(
OneAnd(q, qs.toVector) map { case (tpid, predicate) =>
fr"($tpid = tpid AND (" ++ predicate ++ fr"))"
fr"($tpid = cst.tpid AND (" ++ predicate ++ fr"))"
},
fr" OR ",
)
Expand Down Expand Up @@ -730,7 +730,7 @@ private object OracleQueries extends Queries {
}
case MatchedQueryMarker.Unused =>
val NonEmpty(nequeries) = queries
queryByCondition[SurrogateTpId](fr"tpid", nequeries)
queryByCondition[SurrogateTpId](fr"cst.tpid", nequeries)
}
}

Expand Down

0 comments on commit d26d36e

Please sign in to comment.