title: How to find the columns that need to be indexed?
body: <p>I'm starting to learn SQL and relational databases. Below is the table that I have, and it has around 10 million records. My composite key is <code>(reltype, from_product_id, to_product_id)</code>.</p>
  
  <p>What strategy should I follow while selecting the columns that needs to be indexed? Also, I have documented the operations that would be performed on the table. Please help in determining which columns or combination of columns that need to be indexed?</p>
  
  <p>Table DDL is shown below.</p>
  
  <p>Table name: <code>prod_rel</code>.</p>
  
  <p>Database schema name : <code>public</code></p>
  
  <pre><code>CREATE TABLE public.prod_rel (
  reltype varchar NULL,
  assocsequence float4 NULL,
  action varchar NULL,
  from_product_id varchar NOT NULL,
  to_product_id varchar NOT NULL,
  status varchar NULL,
  starttime varchar NULL,
  endtime varchar null,
  primary key reltype, from_product_id, to_product_id)
  );
  </code></pre>
  
  <p>Operations performed on table:</p>
  
  <pre><code>select distinct(reltype ) 
  from public.prod_rel; 
  
  update public.prod_rel  
     set status = ? , starttime = ? 
  where from_product_id = ?;
  
  update public.prod_rel  
     set status = ? , endtime = ? 
  where from_product_id = ?;
  
  select * 
  from public.prod_rel  
  where from_product_id  in (select distinct (from_product_id) 
                             from public.prod_rel 
                             where status = ? 
                             and action in ('A', 'E', 'C', 'P') 
                             and reltype = ? 
                             fetch first 1000 rows only);
  </code></pre>
  
  <p>Note: I'm not performing any JOIN operations. Also please ignore the uppercase for table or column names. I'm just getting started.</p>