-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigration.sql
59 lines (55 loc) · 1.17 KB
/
migration.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- permutation table:
UPDATE
word
SET
permutation = subquery.normalized
FROM (
SELECT
p.normalized,
p.permutation
FROM
permutation p
JOIN word w ON p.permutation = w.text
WHERE
w.permutation IS NULL
LIMIT 100000) AS subquery
WHERE
word.permutation IS NULL
AND word.text = subquery.permutation;
SELECT
COUNT(*) FILTER (
WHERE w.permutation IS NULL) count_nulls
,
COUNT(*) FILTER (
WHERE w.permutation IS NOT NULL) count_not_nulls
FROM
word w;
-- normalized table:
-- normalized original
UPDATE
word
SET
normalized = subquery.normalized
FROM (
SELECT
n.normalized,
n.original
FROM
normalized n
JOIN word w ON n.original = w.text
WHERE
w.normalized IS NULL
LIMIT 100000) AS subquery
WHERE
word.normalized IS NULL
AND word.text = subquery.original;
SELECT
COUNT(*) FILTER (
WHERE w.normalized IS NULL) count_nulls
,
COUNT(*) FILTER (
WHERE w.normalized IS NOT NULL) count_not_nulls
FROM
word w;
CREATE INDEX word_permutation_idx ON word (permutation);
CREATE INDEX word_normalized_idx ON word (normalized);