This repository was archived by the owner on Jan 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsql_fixes.sql
More file actions
51 lines (44 loc) · 1.83 KB
/
sql_fixes.sql
File metadata and controls
51 lines (44 loc) · 1.83 KB
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
# rename table
RENAME TABLE histories TO histories_old;
# create new histories table with id as primary key
create table histories (
id int(10) unsigned not null AUTO_INCREMENT,
package VARCHAR(100) NOT NULL,
summary text NOT NULL,
checks text,
check_details text,
date_updated datetime NOT NULL,
primary key (id)
);
# move data from old table into new table
SET AUTOCOMMIT = 0; SET UNIQUE_CHECKS=0; SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE histories CONVERT TO CHARACTER SET utf8;
INSERT INTO histories (package,summary,checks,check_details,date_updated) SELECT package,summary,checks,check_details,date_updated FROM histories_old;
# maybe can do above but with only data from last 30 days?
-- INSERT INTO histories (package,summary,checks,check_details,date_updated)
-- SELECT package,summary,checks,check_details,date_updated
-- FROM histories_old
-- WHERE date_updated > NOW() - INTERVAL 1 MONTH;
SET FOREIGN_KEY_CHECKS=1; SET UNIQUE_CHECKS=1; COMMIT; SET AUTOCOMMIT = 1;
# create multi-column index to speed up queries
CREATE INDEX pkg_date ON histories (package,date_updated);
# get deets
describe cchecks.histories;
show index from histories;
# this should be very fast if it worked
select count(*) from histories;
# test some queries - should be fast
select package,date_updated from histories where DATE(date_updated) = '2019-09-05' limit 10;
# to file
select * INTO OUTFILE '2019-06-01.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
from histories
where DATE(date_updated) = '2019-06-01';
select package,summary,check_details,date_updated INTO OUTFILE '2019-06-01-nochecks.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
from histories
where DATE(date_updated) = '2019-06-01';
# drop old table
DROP TABLE histories_old;