Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add index which nerfs a query run on reservation
Previously doing a full table scan which was executing in about 660ms, now taking about 10ms.
- Loading branch information
1 parent
6e2de42
commit 3062e6b
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
-- ----------------------------------------------------------------------------- | ||
-- Hey! | ||
-- | ||
-- This is a new patch-creation script which SHOULD stop double-patching and | ||
-- running patches out-of-order. | ||
-- | ||
-- If you're running patches, please close this file, and run this from the | ||
-- command line: | ||
-- $ mysql -u USERNAME -p SCHEMA < patchXX-this-file.sql | ||
-- where: | ||
-- USERNAME = a user with CREATE/ALTER access to the schema | ||
-- SCHEMA = the schema to run the changes against | ||
-- patch-XX-this-file.sql = this file | ||
-- | ||
-- If you are writing patches, you need to copy this template to a numbered | ||
-- patch file, update the patchversion variable, and add the SQL code to upgrade | ||
-- the database where indicated below. | ||
|
||
DROP PROCEDURE IF EXISTS SCHEMA_UPGRADE_SCRIPT; | ||
DELIMITER ';;' | ||
CREATE PROCEDURE SCHEMA_UPGRADE_SCRIPT() BEGIN | ||
-- ------------------------------------------------------------------------- | ||
-- Developers - set the number of the schema patch here! | ||
-- ------------------------------------------------------------------------- | ||
DECLARE patchversion INT DEFAULT 17; | ||
-- ------------------------------------------------------------------------- | ||
-- working variables | ||
DECLARE currentschemaversion INT DEFAULT 0; | ||
DECLARE lastversion INT; | ||
|
||
-- check the schema has a version table | ||
IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'schemaversion' AND table_schema = DATABASE()) THEN | ||
SIGNAL SQLSTATE '45000' SET message_text = 'Please ensure patches are run in order! This database does not have a schemaversion table.'; | ||
END IF; | ||
|
||
-- get the current version | ||
SELECT version INTO currentschemaversion FROM schemaversion; | ||
|
||
-- check schema is not ahead of this patch | ||
IF currentschemaversion >= patchversion THEN | ||
SIGNAL SQLSTATE '45000' SET message_text = 'This patch has already been applied!'; | ||
END IF; | ||
|
||
-- check schema is up-to-date | ||
SET lastversion = patchversion - 1; | ||
IF currentschemaversion != lastversion THEN | ||
SET @message_text = CONCAT('Please ensure patches are run in order! This patch upgrades to version ', patchversion, ', but the database is not version ', lastversion); | ||
SIGNAL SQLSTATE '45000' SET message_text = @message_text; | ||
END IF; | ||
|
||
-- ------------------------------------------------------------------------- | ||
-- Developers - put your upgrade statements here! | ||
-- ------------------------------------------------------------------------- | ||
|
||
create index pend_reserved on request (reserved); | ||
|
||
-- ------------------------------------------------------------------------- | ||
-- finally, update the schema version to indicate success | ||
UPDATE schemaversion SET version = patchversion; | ||
END;; | ||
DELIMITER ';' | ||
CALL SCHEMA_UPGRADE_SCRIPT(); | ||
DROP PROCEDURE IF EXISTS SCHEMA_UPGRADE_SCRIPT; |