improves the speed of data retrieval operations on a database table at the cost of additional writes and storage space to maintain the index data structure (Wikipedia)
node • All keys are sorted Leaf node • points to data in the disk • same distance from the root B+ Tree with N = 100 with tree depth 5 can support 10,000,000,000 records
holds physical page of the row • Secondary ◦ Leaf node holds primary key value and selected column • Composite (multicolumn) ◦ index(a,b) • Covering ◦ all data selected in query are ‘covered’ by indexes • Fulltext Index (CHAR, VARCHAR, TEXT) ◦ Inverted index (not b+tree)
last_name CHAR(30) NOT NULL, first_name CHAR(30) NOT NULL, PRIMARY KEY (id), INDEX name (last_name,first_name) ); Good SELECT * FROM test WHERE last_name='Widenius' AND first_name='Michael'; SELECT * FROM test WHERE last_name='Widenius' AND (first_name='Michael' OR first_name='Monty'); Bad SELECT * FROM test WHERE first_name='Michael'; SELECT * FROM test WHERE last_name='Widenius' OR first_name='Michael';
by indexes CREATE TABLE test2 ( id INT NOT NULL, Continent CHAR(30) NOT NULL, Population CHAR(30) NOT NULL, Name CHAR(30) NOT NULL, PRIMARY KEY (id), INDEX name (Contient ,Population, Name) ); Good SELECT Name FROM test2 WHERE Continent=’Asia’' AND Population > 100000; Bad SELECT * FROM test2 WHERE Continent='Asia';