Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since this is your version control, I am guessing you probably don't have more than a couple hundred thousand rows in the table. It wouldn't be the end of the world to run through both tables, but like Peter Schott says, it would be good index Revision:</p> <pre><code>CREATE nonclustered index &lt;name&gt; on SubversionLog (revision) CREATE nonclustered index &lt;name&gt; on PathsLog (revision) </code></pre> <p>From personal experience, I don't think that doing a few string manipulations is severely slowing you down. I do think creating multiple temporary tables is slowing you down, since you are creating a new row for most rows in your original tables, and your temp tables are not indexed. Hence, I recommend getting rid of those temporary tables, and simplifying your query:</p> <pre><code>;with filteredData as ( SELECT [path], Substring([path], 0, Len([path]) - Charindex('/', Reverse([path])) + 1) AS [Directory], CONVERT(CHAR(4), [logdate], 120) + '-' + CONVERT(CHAR(2), [logdate], 110) AS [Month] FROM [subversionlog] JOIN [pathslog] ON [subversionlog].[revision] = [pathslog].[revision] WHERE [path] LIKE '/%/%/%/_%' ), countRevisions as ( SELECT [month], [directory], count(*) as [Count] FROM filteredData GROUP BY [MONTH], [directory] ), rankDirectories as ( SELECT *, RANK() over (partition by month order by count desc) as [Rank] from countRevisions ) select [month], [directory], [count] from rankDirectories WHERE [rank] = 1 </code></pre> <p>EDIT:</p> <p>I don't think there's much more you can do without caching some results. You should take a look at the query plan to see what needs to be optimized. I am guessing it's in the grouping, ordering, and/or ranking, possibly joining or key lookup. For the key lookup and joining, you can create covering indices. For the other stuff, you'll need to cache the results. I would not cache with a real table since that would mean an extra table to keep up to date. Instead, I would use a materialized view so that SQL Server keeps it updated for you. Sure this means that updates would be slower, but at a few updates a minute (for a source control log), I don't think this would be a huge problem.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload