Note that there are some explanatory texts on larger screens.

plurals
  1. POBig Table Advice (SQL Server)
    primarykey
    data
    text
    <p>I'm experiencing massive slowness when accessing one of my tables and I need some re-factoring advice. Sorry if this is not the correct area for this sort of thing.</p> <p>I'm working on a project that aims to report on server performance statistics for our internal servers. I'm processing windows performance logs every night (12 servers, 10 performance counters and logging every 15 seconds). I'm storing the data in a table as follows:</p> <pre><code>CREATE TABLE [dbo].[log]( [id] [int] IDENTITY(1,1) NOT NULL, [logfile_id] [int] NOT NULL, [test_id] [int] NOT NULL, [timestamp] [datetime] NOT NULL, [value] [float] NOT NULL, CONSTRAINT [PK_log] PRIMARY KEY CLUSTERED ( [id] ASC )WITH FILLFACTOR = 90 ON [PRIMARY] ) ON [PRIMARY] </code></pre> <p>There's currently 16,529,131 rows and it will keep on growing.</p> <p>I access the data to produce reports and create graphs from coldfusion like so:</p> <pre><code>SET NOCOUNT ON CREATE TABLE ##RowNumber ( RowNumber int IDENTITY (1, 1), log_id char(9) ) INSERT ##RowNumber (log_id) SELECT l.id FROM log l, logfile lf WHERE lf.server_id = #arguments.server_id# and l.test_id = #arguments.test_id#" and l.timestamp &gt;= #arguments.report_from# and l.timestamp &lt; #arguments.report_to# and l.logfile_id = lf.id order by l.timestamp asc select rn.RowNumber, l.value, l.timestamp from log l, logfile lf, ##RowNumber rn where lf.server_id = #arguments.server_id# and l.test_id = #arguments.test_id# and l.logfile_id = lf.id and rn.log_id = l.id and ((rn.rownumber % #modu# = 0) or (rn.rownumber = 1)) order by l.timestamp asc DROP TABLE ##RowNumber SET NOCOUNT OFF </code></pre> <p>(for not CF devs <code>#value#</code> inserts <code>value</code> and <code>##</code> maps to <code>#</code>)</p> <p>I basically create a temporary table so that I can use the rownumber to select every x rows. In this way I'm only selecting the amount of rows I can display. this helps but it's still very slow.</p> <p>SQL Server Management Studio tells me my index's are as follows (I have pretty much no knowledge about using index's properly):</p> <pre><code>IX_logfile_id (Non-Unique, Non-Clustered) IX_test_id (Non-Unique, Non-Clustered) IX_timestamp (Non-Unique, Non-Clustered) PK_log (Clustered) </code></pre> <p>I would be very grateful to anyone who could give some advice that could help me speed things up a bit. I don't mind re-organising things and I have complete control of the project (perhaps not over the server hardware though).</p> <p>Cheers (sorry for the long post)</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.
 

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