Skip to content

Commit

Permalink
Refresh json API materialized view on statement
Browse files Browse the repository at this point in the history
I haven’t found any conclusive information as to why ON COMMIT doesn’t
work incrementally but
https://docs.oracle.com/en/database/oracle/oracle-database/19/adjsn/json-query-rewrite-use-materialized-view-json_table.html#GUID-8B0922ED-C0D1-45BD-9588-B7719BE4ECF0
recommends that for rewriting (which isn’t what we do here but both
involve a materialized view on json_table).

Benchmarks:

before:
InsertBenchmark.run         1000          1            1000  avgt    5  0.327 ± 0.040   s/op
InsertBenchmark.run         1000          3            1000  avgt    5  0.656 ± 0.043   s/op
InsertBenchmark.run         1000          5            1000  avgt    5  1.034 ± 0.051   s/op
InsertBenchmark.run         1000          7            1000  avgt    5  1.416 ± 0.106   s/op
InsertBenchmark.run         1000          9            1000  avgt    5  1.734 ± 0.143   s/op
QueryBenchmark.run          1000         10             N/A  avgt    5  0.071 ± 0.016   s/op

After:
Benchmark            (batchSize)  (batches)  (numContracts)  Mode  Cnt  Score   Error  Units
InsertBenchmark.run         1000          1            1000  avgt    5  0.217 ± 0.034   s/op
InsertBenchmark.run         1000          3            1000  avgt    5  0.232 ± 0.027   s/op
InsertBenchmark.run         1000          5            1000  avgt    5  0.226 ± 0.051   s/op
InsertBenchmark.run         1000          7            1000  avgt    5  0.225 ± 0.048   s/op
InsertBenchmark.run         1000          9            1000  avgt    5  0.232 ± 0.021   s/op
QueryBenchmark.run          1000         10             N/A  avgt    5 0.080 ± 0.014   s/op

The difference in query times is just noise and changes across runs.

So we get the expected behavior of inserts being independent of the
total ACS size now. We could still explore if we gain something by
avoiding the materialized view to reduce constant factors but that’s
much less of an issue.

fixes #10243

changelog_begin
changelog_end
  • Loading branch information
cocreature committed Jul 15, 2021
1 parent 814442e commit fe2b9e7
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -627,14 +627,10 @@ private object OracleQueries extends Queries {
,${jsonColumn(sql"observers")}
"""

private[this] def stakeholdersPrep = DoMagicSetup(
sql"""CREATE MATERIALIZED VIEW LOG ON contract"""
)

private[this] def stakeholdersView = CreateMaterializedView(
"contract_stakeholders",
sql"""CREATE MATERIALIZED VIEW contract_stakeholders
BUILD IMMEDIATE REFRESH FAST ON COMMIT AS
BUILD IMMEDIATE REFRESH FAST ON STATEMENT AS
SELECT contract_id, stakeholder FROM contract,
json_table(json_array(signatories, observers), '$$[*][*]'
columns (stakeholder $partyType path '$$'))""",
Expand All @@ -645,7 +641,7 @@ private object OracleQueries extends Queries {
)

protected[this] override def initDatabaseDdls =
super.initDatabaseDdls ++ Seq(stakeholdersPrep, stakeholdersView, stakeholdersIndex)
super.initDatabaseDdls ++ Seq(stakeholdersView, stakeholdersIndex)

protected[this] type DBContractKey = JsValue

Expand Down

0 comments on commit fe2b9e7

Please sign in to comment.