title: How to create a multicolumn GiST index in Postgresql
body: <p>The postgresql <a href="https://www.postgresql.org/docs/current/static/indexes-multicolumn.html" rel="noreferrer">documentation</a> specifies that a GiST index can have multiple columns, but does not provide an example of what this might look like.</p>
  
  <p>I have a table that tracks assets owned by different customers.</p>
  
  <pre><code>CREATE TABLE asset (
      id serial PRIMARY KEY,
      description text NOT NULL,
      customer_id uuid NOT NULL
  );
  </code></pre>
  
  <p>I'm writing a query that allows a customer to search for an asset based on words in it's description.</p>
  
  <pre><code>SELECT *
  FROM asset
  WHERE to_tsvector('english', asset.description) @@ plainto_tsvector('english', ?)
  AND asset.customer_id = ?;
  </code></pre>
  
  <p>Were this a non-tsvector query, I'd build a simple multicolumn index</p>
  
  <pre><code>CREATE INDEX idx_name ON asset(customer_id, description);
  </code></pre>
  
  <p>I can create an index <em>only</em> on the tsvector:</p>
  
  <pre><code>CREATE INDEX idx_name ON asset USING gist(to_tsvector('english', asset.description));
  </code></pre>
  
  <p>However, the query optimizer doesn't use the gist index, because it seems to want to do <code>customer_id</code> filtering first. Is there a way that I can include the non-tsvector field <code>customer_id</code> in the gist index, somehow, or am I out of luck?</p>