title: SQL Server table partitioning based on a modulus function?
body: <p>I've got a really large table (10+ million rows) that is starting to show signs of performance degradation for queries. Since this table will probably double or triple in size relatively soon I'm looking into partitioning the table to squeeze out some query performance.</p>
  
  <p>The table looks something like this:</p>
  
  <pre><code>CREATE TABLE [my_data] (
      [id] [int] IDENTITY(1,1) NOT NULL,
      [topic_id] [int] NULL,
      [data_value] [decimal](19, 5) NULL
  )
  </code></pre>
  
  <p>So, a bunch of values for any given topic. Queries on this table will always be by topic ID, so there's a clustered index on (id, topic_id).</p>
  
  <p>Anyway, since topic IDs aren't bounded (any number of topics could be added) I'd like to try partitioning this table on a modulus function of the topic IDs. So something like:</p>
  
  <pre><code>topic_id % 4 == 0 =&gt; partition 0
  topic_id % 4 == 1 =&gt; partition 1
  topic_id % 4 == 2 =&gt; partition 2
  topic_id % 4 == 3 =&gt; partition 3
  </code></pre>
  
  <p>However, I haven't seen any way to tell "create partition function" or "create partition scheme" to perform this operation when deciding on a partition.</p>
  
  <p>Is this even possible? How can we make a partition function based on an operation performed on the input value?</p>