Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/Time complexity of queryContractKeyForum ↗

Time complexity of queryContractKey

App Development3 posts186 views2 likesLast activity Nov 2023
SA
SaiOP
Nov 2023

Hi all,

I’m trying to do some performance analysis involving contract query. I’m wondering what’s the time complexity of querying by contract key? The documentation says contract key is similar to database primary key (which I believe is usually hashed index), does that mean queryContractKey has time complexity of O(1)?

Thank you!

BE
bernhard
Nov 2023

Hi Sai,

In what context are you asking? Daml Script, Triggers, Typescript, etc.?
Generally speaking queryContractKey has order O(log(N)) as it’s an index lookup and database indices are typically b-trees.

More important maybe is that the complexity of queryContractId and queryContractKey are the same.

SA
Sai
Nov 2023

Hi @bernhard ,

Yes I’m looking for the general time complexity order, so I believe running in Daml Script or Typescript shouldn’t be an impact factor.

Thank you for the answer!

← Back to Discussions