Some years ago, I wrote a generic query to fetch posts in a given month.
WITH allData AS (
SELECT
ROW_NUMBER() OVER (ORDER BY P.Id) AS row
, P.Id
, P.PostTypeId
, P.ParentId
, P.AcceptedAnswerId
, P.CreationDate
, P.OwnerUserId
, P.Tags
, P.ClosedDate
FROM Posts AS P
WHERE YEAR(P.CreationDate) = (##Year:INT?1##) AND MONTH(P.CreationDate) = (##Month:INT?1##)
)
SELECT *
FROM allData
WHERE row >= 1 + 50000*(##StartPage:INT?1## - 1)
ORDER BY row
I have used this query numerous times over the years without issue.
Yesterday and today, however, the query gives me the error
Line 0: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Note
The problem seems to lie with the first WHERE
clause. (WHERE YEAR(P.CreationDate) = (##Year:INT?1##) AND MONTH(P.CreationDate) = (##Month:INT?1##)
). Without this, the query runs fine.
WHERE P.Id >= X and P.Id < Y
. I have to mess around to find the right values for X and Y, but it works. (I'm dumping the data into R where I'm studying trending tags.)