title: Faster 'select distinct thing_id,thing_name from table1' in oracle
body: <p>I have this query:</p>
  
  <pre><code>select distinct id,name from table1
  </code></pre>
  
  <p>For a given ID, the name will always be the same.  Both fields are indexed.  There's no separate table that maps the id to the name.  The table is very large (10 of millions of rows), so the query could take some time.</p>
  
  <p>This query is very fast, since it's indexed:</p>
  
  <pre><code>select distinct name from table1
  </code></pre>
  
  <p>Likewise for this query:</p>
  
  <pre><code>select distinct id from table1
  </code></pre>
  
  <p>Assuming I can't get the database structure changed (a very safe assumption) what's a better way to structure the first query for performance?</p>
  
  <p>Edit to add a sanitized desc of the table:</p>
  
  <pre>
  
  Name                           Null     Type
  ------------------------------ -------- ----------------------------
  KEY                            NOT NULL NUMBER
  COL1                           NOT NULL NUMBER
  COL2                           NOT NULL VARCHAR2(4000 CHAR)
  COL3                           VARCHAR2(1000 CHAR)
  COL4                           VARCHAR2(4000 CHAR)
  COL5                           VARCHAR2(60 CHAR)
  COL6                           VARCHAR2(150 CHAR)
  COL7                           VARCHAR2(50 CHAR)
  COL8                           VARCHAR2(3 CHAR)
  COL9                           VARCHAR2(3 CHAR)
  COLA                           VARCHAR2(50 CHAR)
  COLB                           NOT NULL DATE
  COLC                           NOT NULL DATE
  COLD                           NOT NULL VARCHAR2(1 CHAR)
  COLE                           NOT NULL NUMBER
  COLF                           NOT NULL NUMBER
  COLG                           VARCHAR2(600 CHAR)
  ID                             NUMBER
  NAME                           VARCHAR2(50 CHAR)
  COLH                           VARCHAR2(3 CHAR)
  
  20 rows selected
  </pre>