title: speeding up recursive query/ looping through values
body: <p>Suppose table with structure like this:</p>
  
  <pre><code>create table tab1
  (
  id int,
  valid_from timestamp
  )
  </code></pre>
  
  <p>I need to build query such that in case there is a duplicity over pair (id,valid_from), e.g.</p>
  
  <pre><code>id    valid_from
  1     2000-01-01 12:00:00
  1     2000-01-01 12:00:00
  </code></pre>
  
  <p>then one second needs to be added to subsequent rows to valid_from column. 
  For example if there are three duplicate rows, the result should be as follows </p>
  
  <pre><code>id    valid_from
  1     2000-01-01 12:00:00
  1     2000-01-01 12:00:01
  1     2000-01-01 12:00:02
  </code></pre>
  
  <p>Tried running a recursive cte query but since for some cases there is a large number of duplicate values (for current data set about 160 for some cases of (id,valid_from)), it is really slow.
  Thanks</p>