install_rewriter.sql 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Copyright (c) 2015, 2021, Oracle and/or its affiliates.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License, version 2.0,
  4. as published by the Free Software Foundation.
  5. This program is also distributed with certain software (including
  6. but not limited to OpenSSL) that is licensed under separate terms,
  7. as designated in a particular file or component or in included license
  8. documentation. The authors of MySQL hereby grant you an additional
  9. permission to link the program and your derivative works with the
  10. separately licensed software that they have included with MySQL.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License, version 2.0, for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  18. CREATE DATABASE IF NOT EXISTS query_rewrite;
  19. CREATE TABLE IF NOT EXISTS query_rewrite.rewrite_rules (
  20. id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  21. pattern VARCHAR(5000) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  22. pattern_database VARCHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin,
  23. replacement VARCHAR(5000) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  24. enabled ENUM('YES', 'NO') CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
  25. DEFAULT 'YES',
  26. message VARCHAR(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin,
  27. pattern_digest VARCHAR(64),
  28. normalized_pattern VARCHAR(100)
  29. ) DEFAULT CHARSET = utf8mb4 ENGINE = INNODB;
  30. INSTALL PLUGIN rewriter SONAME 'rewriter.dll';
  31. CREATE FUNCTION load_rewrite_rules RETURNS STRING
  32. SONAME 'rewriter.dll';
  33. DELIMITER //
  34. CREATE PROCEDURE query_rewrite.flush_rewrite_rules()
  35. BEGIN
  36. DECLARE message_text VARCHAR(100);
  37. COMMIT;
  38. SELECT load_rewrite_rules() INTO message_text;
  39. IF NOT message_text IS NULL THEN
  40. SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = message_text;
  41. END IF;
  42. END //
  43. DELIMITER ;