title: How can I reduce this Query's operation time with Indexes?
body: <p>I have a really simple query and a pool of 8718 registers, the run time for it is approximately 7 seconds, and I don't understand the reason behind it. I've tried using Indexes utilizing the document type, state and reference (basically the variables from the WHERE clause). And even tho the index is utilized, nor the cardinality or cost are reduced whatsoever. </p>
  
  <p>I can't see any way to reduce the query size by itself, so I'm guessing it has to be an Index issue. I'd appreciate any kind of help.</p>
  
  <pre><code>    SELECT TELEPHONE AS telephone, 
      GROUP AS group, 
      UPPER(GROUPNAME) AS groupName, 
      RECEIPTID AS receiptId, 
      sum(CHARGED) AS charged, 
      sum(PAID) AS paid, 
      YEAR as year, 
      MONTH as month 
  
      FROM PERMANENT_TABLE 
      where DOC_TYPE in('0', '01', '04') 
      and state = X 
      and reference = XXXXX
      GROUP BY TELEPHONE, RECEIPTID, GROUP, GROUPNAME, YEAR, 
      MONTH;
  </code></pre>
  
  <p>Cardinality/Cost for:</p>
  
  <p>Group by: 8718/7893
  Index: 30741/6168</p>
  
  <p>Thank you for your time, if any additional information is required, please let me know.</p>