Time complexity of queryContractKey

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!

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.

2 Likes

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!