Note that there are some explanatory texts on larger screens.

plurals
  1. POVery Slow Sql Server Query
    primarykey
    data
    text
    <p>I have 2 tables resulted from merging the following tables:</p> <pre><code>Authors -Aid bigint -Surname nvarchar(500) -Email nvarchar(500) Articles -ArId varchar(50) -Year int -……Some other fields…… ArticleAuthors -ArId varchar(50) -Aid bigint Classifications -ClassNumber int -ClassDescription nvarchar(100) ClassArticles -ArId varchar(50) -ClassNumber int </code></pre> <p>After denormalizing these tables the resulted tables were:</p> <pre><code>Articles -FieldId int -ArId varchar(50) -ClassNumber int (Foreign key from the Classifications table) -Year int Authors -FieldId int -ArId varchar(50) (Foreign key from the Articles table) -Aid bigint -Surname nvarchar(500) -Email nvarchar(500) -Year int </code></pre> <p>Here are the conditions of the data within the resulted tables:</p> <ul> <li>SQL Server 2008 database</li> <li>The relationships between the two tables are applied physically</li> <li>The Authors table has 50 million records</li> <li>The Articles table has 20 million records</li> <li>The author has written many articles during the same year with different emails</li> <li>There are authors in the authors table with ArIds that don’t reference ArIds in the Articles table (Orphan records)</li> <li>The values within the Year fields ranges from 2002 and 2009</li> <li>The Articles table has a unique clustered index on the [FieldId and Year] fields and this index created on 9 partitions (1 partition per year)</li> <li>The Authors table has a non-unique clustered index on the [Year, ArId, Aid] fields and this index is created on the same 9 partition as the Articles table (1 partition per year)</li> </ul> <p>The question is:</p> <ul> <li><p>We need to create a stored procedure that gets the following result from the two tables [Aid,Surname,Email] under the following conditions:</p></li> <li><p>Authors that have written articles during and after a specific year (AND)</p></li> <li>The total number of articles for the author is greater than a specific number (AND)</li> <li>The count of the articles written by the author under a specific ClassNumber is greater than a specific percentage of the total number of his articles (AND)</li> <li>Get only the most recent email of the author (in the last year during which he has written an article)</li> <li>If the author has more than one email in the same year, get them all.</li> </ul> <p>We need the query to take the least possible time</p> <p>If anyone can help, Thank you very much.</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. 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