Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you say <i>The field_instances table is indexed on both form_instance_id and field_id</i> you mean that there are separate indexes on form_instance_id and field_id on that table?</p> <p>Try dropping the index on <code>form_instance_id</code> and put a concatenated index on <code>(form_instance_id, field_id)</code>.</p> <p>An index works by giving you a quick lookup that tells you where the rows are that match your index. It then has to fetch through those rows to do what you want. So you always want your index to be as specific as possible. If you put two indexes on the table, you'll have two different ways to do a lookup, but a query will usually only take advantage of one of them. If you put a <em>concatenated</em> index on the table, you'll be able to look up on the first field in the index, the first two fields, etc efficiently. (So a concatenated index on <code>(a, b)</code> gives you fast lookups on <code>a</code>, even faster lookups on both <code>a</code> and <code>b</code>, but doesn't help you look things up on <code>b</code>)</p> <p>Right now it is figuring out all possible things in <code>form_instances</code> that have the right state. It separately figures out all of the <code>field_instances</code> that have the right field id. It then does a hash join. For this makes a lookup hash from one result set, and scans the other for matches.</p> <p>With my suggestion it should figure out all possible <code>form_instances</code> of interest. It will then go to the index, and figure out all of the <code>field_instances</code> that match on <strong>both</strong> the form instance and field id, and then it will find exactly the results of interest. Because the index is more specific, the database will have fewer rows of data to deal with to process your query.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload