samedi 2 septembre 2017

Performant stable random sort in SQL Server?

I want to query a rather large table (millions of rows), providing a seed value, in a manner that will guarantee a random order - but one that is the same across multiple queries as long as the same seed is used.

The best I've come up with so far is

SELECT TOP n *
      FROM tbl t
  ORDER BY t.int_column % seed, t.int_column

Is this a usable approach, both from a performance standpoint and a somewhat-uniform distribution of result rows over different seeds?




Aucun commentaire:

Enregistrer un commentaire