Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do any databases support automatic Index Creation?

Why don't databases automatically index tables based on query frequency? Do any tools exist to analyze a database and the queries it is receiving, and automatically create, or at least suggest which indexes to create?

I'm specifically interested in MySQL, but I'd be curious for other databases as well.

like image 306
jcnnghm Avatar asked Oct 23 '08 21:10

jcnnghm


People also ask

Can indexes be created automatically?

Oracle enforces a UNIQUE key or PRIMARY KEY integrity constraint by creating a unique index on the unique key or primary key. This index is automatically created by Oracle when the constraint is enabled; no action is required by the issuer of the CREATE TABLE or ALTER TABLE statement to create the index.

Does SQL create indexes automatically?

A unique index is automatically created when you define a primary key or unique constraint: Primary key: When you define a primary key constraint on one or more columns, SQL Server automatically creates a unique, clustered index if a clustered index does not already exist on the table or view.

Which index is created automatically by the database server?

Implicit indexes are indexes that are automatically created by the database server when an object is created. Indexes are automatically created for primary key constraints and unique constraints.

Does MySQL automatically index?

Yes, primary key is automatically indexed in MySQL because primary key, index, etc gets stored into B-trees. All engines including InnoDB as well as MyISAM automatically supports the primary key to be indexed. The primary key is implicitly indexed in InnoDB, MyISAM, and other engines.


1 Answers

That is a best question I have seen on stackoverflow. Unfortunately I don't have an answer. Google's bigtable does automatially index the right columns, but BigTable doesn't allow arbitrary joins so the problem space is much smaller.

The only answer I can give is this:

One day someone asked, "Why can't the computer just analyze my code and and compile & statically type the pieces of code that run most often?"

People are solving this problem today (e.g. Tamarin in FF3.1), and I think "auto-indexing" relational databases is the same class of problem, but it isn't as much a priority. A decade from now, manually adding indexes to a database will be considered a waste of time. For now, we are stuck with monitoring slow queries and running optimizers.

like image 125
jcampbell1 Avatar answered Sep 22 '22 02:09

jcampbell1