Skip to content

Instantly share code, notes, and snippets.

@rohitpaulk
Created February 19, 2018 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rohitpaulk/7073ca9330a240c1022479943099acec to your computer and use it in GitHub Desktop.
Save rohitpaulk/7073ca9330a240c1022479943099acec to your computer and use it in GitHub Desktop.
use teamcom_shard_01;
DROP TABLE IF EXISTS contacts_test;
CREATE TABLE contacts_test (
email VARCHAR(255) NOT NULL,
public TINYINT(1), -- Values are either NULL, or True
workspace_id INT(11) unsigned NOT NULL,
creator INT(11) unsigned NOT NULL
, UNIQUE KEY `only_one_public` (workspace_id, public, email)
, UNIQUE KEY `creator_and_email` (workspace_id, creator, email)
);
EXPLAIN EXTENDED SELECT *
FROM contacts_test
WHERE workspace_id = 1234
AND (public = 1)
\G;
-- Expected that the `workspace_id, public, email` index will be used. However,
-- MySQL prefers the `workspace_id, creator, email` index.
show keys from contacts;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment