Does dbms create separate files for index entries and data?
-
I have a table with data ( location , data ) and suppose database creates index as shown. will the dbms create separate index file and data file ? If not then how will it store data and apply indexing on that ? Image courtesy : Sams Teach Yourself SQL in 24 Hours
-
Answer:
Let's assume we're talking about most common B+ tree based indexes. Having separate files for indexes means each index has its own page space, so free pages from one index can't be reused by another. Pros: Since OS periodically defragments files, you might expect lower index fragmentation here; actually, a lot depends on the implementation, but it's pretty natural to expect this for indexes which mostly grow at the end (e.g. primary indexes of tables with high insert/delete ratios) It's cheaper to fully defragment one particular index in this case. If there is a single file per database (Microsoft SQL Server), there is single shared page space. Pros: Free pages can be reused by different indexes DBMS gets more control over index index page allocation strategy. There are some intermediate options - e.g. MySQL supports file-per-table mode w/ InnoDB storage engine. And concerning this part: > If not then how will it store data and apply indexing on that? Today I wrote a very comprehensive answer that should fully explain this:
Alex Yakunin at Quora Visit the source
Other answers
In general in different DBMS systems different storage engines store data differently. Oracle would store table and index data in tablespaces. Tablespace can use one of more data files. Table Data and Index Data can be stored in the same or different table spaces - per DBA's discretion. Oracle also has way to mix index and data together for better performance - check out Index Organized Tables (IOT) MySQL MyISAM storage engine has ability to store table and index data in separate files and InnoDB also uses tablespaces. DB2 Database also can store table and index data either in individual files or in tablespaces.
Ron Warshawsky
MySQL's MyISAM does. It's implementation dependent.
Toby Thain
As many have noted, it's entirely implementation dependent. However, the differences mean less than you might think. Whether you use separate files, or have one big file and use your own mechanism for keeping track of which bits of the file contain what and management of free space, it all just comes down to blocks scattered on the disk. If you use separate files, you're making use of the filesystem's inbuilt ability to split the disk into logical files and manage free space. If you use one big file, then you're doing it all yourself, and just using the filesystem as a pool of storage you can request new blocks from (by growing your file), and maybe release them back if you feel genorous. If you go the whole hog and access raw partitions, that's not much different to just using a single large file, except that your free space can't be used by other applications and you might get better control over write caching (which can speed up commit times, but that's another matter). So, clearly, it only makes a difference if you do a better or worse job of it than your filesystem! Using the filesystem may not save you much code, as you probably need free space management within your index/table files anyway to handle deletion of records. But it can still simplify your code when it comes time to drop entire tables or indexes, as you can just ask the filesystem to unlink the entire file, rather than needing to scan through the thing you're deleting and add all its pages back to your own free list. Whether your own bulk-deletion system is more or less efficient than the filesystem's is another question entirely!
Alaric Snell-Pym
Related Q & A:
- What happens when CREATE INDEX gets interrupted (manually or accidentally?Best solution by Database Administrators
- How to separate mongodb data files from the journal?Best solution by dba.stackexchange.com
- How to change column data's as a separate column wise format in a SQL Server?Best solution by stackoverflow.com
- Can I create a separate email address under my current Yahoo address?Best solution by Yahoo! Answers
- What are .cue files and how to separate a large flac file?Best solution by techsupportalert.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.