title: Indexing of tuples in a large PSQL JSONB array
body: <p>I have a JSONB column <code>&quot;deps&quot;</code> like this</p>
  <pre class="lang-json prettyprint-override"><code>[
    [
      {
        &quot;name&quot;: &quot;A&quot;
      },
      &quot;823&quot;
    ],
    [
      {
        &quot;name&quot;: &quot;B&quot;
      },
      &quot;332&quot;
    ],
    [
      {
        &quot;name&quot;: &quot;B&quot;
      },
      &quot;311&quot;
    ]
  ]
  </code></pre>
  <p>The dictionary <code>{&quot;name&quot;: &quot;B&quot;}</code> always comes first in the tuple. The number of tuples (items in the array) varies between zero and 15K</p>
  <p>Is it possible to create an index of the items by <code>&quot;name&quot;</code> field of the dictionary?</p>
  <p>Will such index improve performance of search for all rows containing</p>
  <p><code>&quot;name&quot; = &quot;B&quot;</code> or <code>&quot;name&quot; = &quot;C&quot;</code> ?</p>
  <pre class="lang-sql prettyprint-override"><code>SELECT *
    FROM the_table
   WHERE deps @&gt; ANY (
                      ARRAY [
                             '[[{&quot;name&quot;: &quot;B&quot;}]]',
                             '[[{&quot;name&quot;: &quot;C&quot;}]]'
                            ]::jsonb[]
                     );
  </code></pre>
  <p>I have discovered that the time of query above does not depend much on the size of the array in the ANY argument. It seems that PSQL creates a temporary (?) index when looking for B, consequent lookup for &quot;C&quot; runs fast.
  The table is quite large ~300GB, 25M rows</p>