Skip to content
CCPEDIAby Unity Nodes
App Development

Time complexity of queryContractKey

3 posts214 views2 likesLast activity Nov 2023

  1. SaiOP

    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!

  2. bernhard 2

    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.

  3. Sai

    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!