Skip to content

Commit

Permalink
restore natural join and avoid table aliasing in participant contract…
Browse files Browse the repository at this point in the history
…s queries (#9671) (#9673)

* restore natural join

CHANGELOG_BEGIN
CHANGELOG_END

* JOIN with ON clause rather than NATURAL JOIN so table aliasing will work cross-platform

* scalafmt
  • Loading branch information
dasormeter committed May 12, 2021
1 parent 9ae787d commit 5f53238
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ private[dao] sealed class ContractsReader(
dispatcher.executeSql(metrics.daml.index.db.lookupContractByKeyDbMetrics) {
implicit connection =>
SQL"""select pc.contract_id from #$contractsTable
where #$stakeholdersWhere and pcw.contract_witness in ($readers)
and pc.create_key_hash = ${key.hash}
where #$stakeholdersWhere and contract_witness in ($readers)
and create_key_hash = ${key.hash}
#${sqlFunctions.limitClause(1)}"""
.as(contractId("contract_id").singleOpt)
}
Expand All @@ -74,10 +74,7 @@ private[dao] sealed class ContractsReader(
metrics.daml.index.db.lookupActiveContract,
dispatcher
.executeSql(metrics.daml.index.db.lookupActiveContractDbMetrics) { implicit connection =>
SQL"""select pc.contract_id, pc.template_id, pc.create_argument, pc.create_argument_compression from #$contractsTable
where
pc.contract_id = pcw.contract_id and
pcw.contract_witness in ($readers) and pc.contract_id = $contractId #${sqlFunctions
SQL"""select pc.contract_id, template_id, create_argument, create_argument_compression from #$contractsTable where contract_witness in ($readers) and pc.contract_id = $contractId #${sqlFunctions
.limitClause(1)}"""
.as(contractRowParser.singleOpt)
}
Expand Down Expand Up @@ -105,7 +102,7 @@ private[dao] sealed class ContractsReader(
metrics.daml.index.db.lookupActiveContract,
dispatcher
.executeSql(metrics.daml.index.db.lookupActiveContractDbMetrics) { implicit connection =>
SQL"select pc.contract_id, pc.template_id from #$contractsTable where pcw.contract_witness in ($readers) and pc.contract_id = $contractId #${sqlFunctions
SQL"select contract_id, template_id from #$contractsTable where contract_witness in ($readers) and pc.contract_id = $contractId #${sqlFunctions
.limitClause(1)}"
.as(contractWithoutValueRowParser.singleOpt)
}
Expand Down Expand Up @@ -136,7 +133,7 @@ private[dao] sealed class ContractsReader(

private[dao] object ContractsReader {
private val contractsTable =
"participant_contracts pc, participant_contract_witnesses pcw"
"participant_contracts pc JOIN participant_contract_witnesses pcw ON pcw.contract_id = pc.contract_id"
private val contractWithoutValueRowParser: RowParser[String] =
str("template_id")
private val contractRowParser: RowParser[(String, InputStream, Option[Int])] =
Expand Down

0 comments on commit 5f53238

Please sign in to comment.