forked from trdtnguyen/mysql-plnvm
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall_rewriter.sql.in
49 lines (39 loc) · 1.8 KB
/
install_rewriter.sql.in
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
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
CREATE DATABASE IF NOT EXISTS query_rewrite;
CREATE TABLE IF NOT EXISTS query_rewrite.rewrite_rules (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
pattern VARCHAR(10000) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
pattern_database VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_bin,
replacement VARCHAR(10000) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
enabled ENUM('YES', 'NO') CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
DEFAULT 'YES',
message VARCHAR(1000) CHARACTER SET utf8 COLLATE utf8_bin,
pattern_digest VARCHAR(32),
normalized_pattern VARCHAR(100)
) DEFAULT CHARSET = utf8 ENGINE = INNODB;
INSTALL PLUGIN rewriter SONAME 'rewriter.${DYNLIB_EXTENSION}';
CREATE FUNCTION load_rewrite_rules RETURNS STRING
SONAME 'rewriter.${DYNLIB_EXTENSION}';
DELIMITER //
CREATE PROCEDURE query_rewrite.flush_rewrite_rules()
BEGIN
DECLARE message_text VARCHAR(100);
COMMIT;
SELECT load_rewrite_rules() INTO message_text;
RESET QUERY CACHE;
IF NOT message_text IS NULL THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = message_text;
END IF;
END //
DELIMITER ;
RESET QUERY CACHE;