File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes MySQL indexing - is it a tree? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "MySQL indexing - is it a tree?" Watch "MySQL indexing - is it a tree?" New topic

MySQL indexing - is it a tree?

Ivan Jouikov
Ranch Hand

Joined: Jul 22, 2003
Posts: 269
I have a table,

which will store account stuff, such as address email, name, phone, and whatever the hell I come up with.

So you get the idea, the table will be huge. For every account there will be like 10 different rows.

So, I was wandering, is it the best way to do INDEX(accID), INDEX(name), will that give you a tree structure? Because efficiency here will be the key. I forsee my statements to retrieve an attribute to be something like

SELECT value FROM account_attributes WHERE accID='?' AND name='?'

... Is this how you would do it? Or is there a more efficient way?
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

Creating just the index on accID is enough. The database will get the 10 or so rows and then look through only those for the given name. This happens very quickly.

While, you could do an index of accID and name, it would be roughly 2/3 as large as the full table. So it wouldn't be as fast.

Having 2 separate indexes for accID and name doesn't help you because the database can only use one at a time.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Ivan Jouikov
Ranch Hand

Joined: Jul 22, 2003
Posts: 269
I agree. Here's the link:
subject: MySQL indexing - is it a tree?
It's not a secret anymore!