# Indexing on PQS contract payloads

**URL:** <https://forum.canton.network/t/indexing-on-pqs-contract-payloads/7211>\
**Category:** App Development\
**Tags:** pqs\
**Created:** [April 16, 2024, 5:44am UTC](https://forum.canton.network/t/indexing-on-pqs-contract-payloads/7211 "2024-04-16T05:44:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![huw](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/huw/32/2343_2.png) [@huw](https://forum.canton.network/u/huw)\
**Post date:** [April 16, 2024, 5:44am UTC](https://forum.canton.network/t/indexing-on-pqs-contract-payloads/7211/1 "2024-04-16T05:44:05Z")

</div>

Hi there. I would like to create some indexes for efficient queries on the active contract set using the participant query store. From what I understand, I would need to add an index to one of the tables created by scribe. Which table should I be using? I can see there is a `_creates` table and also various other tables for specific contracts/choice types.

---

<div class="post-metadata">

**Author:** ![sormeter](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/sormeter/32/280_2.png) [@sormeter](https://forum.canton.network/u/sormeter)\
**Post date:** [April 17, 2024, 1:56am UTC](https://forum.canton.network/t/indexing-on-pqs-contract-payloads/7211/2 "2024-04-17T01:56:40Z")

</div>

Some guidance on creation of indexes for PQS can be found in the [Participant Query Store User Guide — Daml SDK 2.8.3 documentation](https://docs.daml.com/query/pqs-user-guide.html#indexing)

The tables you will want to index will depend on your query access pattern, and where you are spotting bottlenecks, and likely specific to a particular contract and relevant fields for that contract.

---

<div class="post-metadata">

**Author:** ![Luciano](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/luciano/32/319_2.png) [@Luciano](https://forum.canton.network/u/Luciano)\
**Post date:** [April 18, 2024, 2:56pm UTC](https://forum.canton.network/t/indexing-on-pqs-contract-payloads/7211/3 "2024-04-18T14:56:45Z")

</div>

Hi Huw. I was in a similar situation myself recently.

There is a PSQL utility function that will help you precisely with this:

```haskell
create_index_for_contract(name text, qname text, expression text, index_type text,
                                                      index_opclass text default '')

```

This allow you to create the indices by specifying the Daml template name directly.

---

<div class="post-metadata">

**Author:** ![huw](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/huw/32/2343_2.png) [@huw](https://forum.canton.network/u/huw)\
**Post date:** [April 29, 2024, 6:06am UTC](https://forum.canton.network/t/indexing-on-pqs-contract-payloads/7211/4 "2024-04-29T06:06:54Z")

</div>

Thanks guys, I will take a look into these solutions
