Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Speeding Up Your Database

Speeding Up Your Database

An interactive and informative talk on how you can implement effective Indexes with SilverStripe for optimal Database performance.

Philipp Krenn

October 16, 2015
Tweet

More Decks by Philipp Krenn

Other Decks in Programming

Transcript

  1. CREATE TABLE `SiteTree_versions` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `RecordID`

    int(11) NOT NULL DEFAULT '0', `Version` int(11) NOT NULL DEFAULT '0', ... PRIMARY KEY (`ID`), KEY `RecordID_Version` (`RecordID`,`Version`), ... ) ENGINE=InnoDB AUTO_INCREMENT=516 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; SELECT ID, RecordID, Version FROM SiteTree_versions WHERE RecordID = 123 AND Version = 4; SELECT ID, RecordID, Version FROM SiteTree_versions WHERE Version = 4;
  2. CREATE TABLE `SiteTree_versions` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `RecordID`

    int(11) NOT NULL DEFAULT '0', `Version` int(11) NOT NULL DEFAULT '0', ... PRIMARY KEY (`ID`), KEY `RecordID_Version` (`RecordID`,`Version`), ... ) ENGINE=InnoDB AUTO_INCREMENT=516 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; SELECT ID, RecordID, Version FROM SiteTree_versions WHERE RecordID = 123 ORDER BY Version DESC LIMIT 1;
  3. CREATE TABLE `SiteTree` ( ... `Title` varchar(255) CHARACTER SET utf8

    DEFAULT NULL, `Created` datetime DEFAULT NULL, ... ) ENGINE=InnoDB AUTO_INCREMENT=516 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
  4. class MyObject extends DataObject { private static $indexes = array(

    '<column-name>' => true, '<index-name>' => array('type' => '<type>', 'value' => '"<column-name>"'), '<index-name>' => 'unique("<column-name>")' ); }
  5. class MyTestObject extends DataObject { private static $db = array(

    'MyField' => 'Varchar', 'MyOtherField' => 'Varchar', ); private static $indexes = array( 'MyIndexName' => array( 'type' => 'index', 'value' => '"MyField","MyOtherField"' ) ); }
  6. Member.php private static $indexes = array( 'Email' => true, //Removed

    due to duplicate null values causing MSSQL problems //'AutoLoginHash' => Array( // 'type'=>'unique', // 'value'=>'AutoLoginHash', // 'ignoreNulls'=>true //) );
  7. CREATE TABLE `Feature` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Created`

    datetime DEFAULT NULL, `LastEdited` datetime DEFAULT NULL, `Category` enum('Shorts','Games','Open','Apps','Visuals','Photos') CHARACTER SET utf8 DEFAULT 'Shorts', ... ) ENGINE=InnoDB AUTO_INCREMENT=1110 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; SELECT ID FROM Feature WHERE Category = "Games";
  8. EXPLAIN SELECT ID FROM Feature WHERE Category = "Games"; id

    select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Feature ALL NULL NULL NULL NULL 787 Using where