Skip to content

Commit d5d167b

Browse files
committed
Fix bug in creation of UserTagQA table.
The answers were not being counted at all. Also, add another compound index.
1 parent 7a3c09b commit d5d167b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

sql/optional_post.sql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- These are the optional post processing tasks which may be performed.
22

33
-- UserTagQA TABLE
4+
-- How many Questions and Answers has the user posted under a given tag.
45
DROP TABLE IF EXISTS UserTagQA;
56
CREATE TABLE UserTagQA (
67
UserId int,
@@ -12,16 +13,18 @@ CREATE TABLE UserTagQA (
1213
INSERT INTO UserTagQA
1314
( SELECT P.ownerUserId AS UserId,
1415
PT.tagId AS TagId,
15-
sum(CASE P.PostTypeId WHEN 1 THEN 1 ELSE 0 END) AS Questions,
16-
sum(CASE P.PostTypeId WHEN 2 THEN 1 ELSE 0 END) AS Answers
17-
FROM Posts P JOIN PostTags PT ON PT.PostId = P.Id
16+
SUM(CASE P.PostTypeId WHEN 1 THEN 1 ELSE 0 END) AS Questions,
17+
SUM(CASE P.PostTypeId WHEN 2 THEN 1 ELSE 0 END) AS Answers
18+
FROM Posts P JOIN PostTags PT ON (PT.PostId = P.Id OR PT.PostId = P.ParentId)
1819
WHERE P.OwnerUserId IS NOT NULL
1920
GROUP BY P.OwnerUserId, PT.TagId
2021
);
2122
CREATE INDEX usertagqa_questions_idx ON UserTagQA USING btree (Questions)
2223
WITH (FILLFACTOR = 100);
2324
CREATE INDEX usertagqa_answers_idx ON UserTagQA USING btree (Answers)
2425
WITH (FILLFACTOR = 100);
26+
CREATE INDEX usertagqa_questions_answers_idx ON UserTagQA USING btree (Questions, Answers)
27+
WITH (FILLFACTOR = 100);
2528

2629

2730
-- QuestionAnswer TABLE

0 commit comments

Comments
 (0)