rss

ERROR 126 (HY000): Incorrect key file for table

Category : MySQL

I had a table with 62 Millions records with total size on disk as 1.2 GB.
What i was doing was joining this table with other table having 80 thousand records.

While running the query the MySQL server showed me an error

ERROR 126 (HY000): Incorrect key file for table

The problem behind this  was related to the size of the temp directory, there was not enough memory on the drive where the temp directory was located.
SOLUTION
Try to change the location of the MySQL tmp directory to a place where there is lots of space. you can do this by editing the MySQL config file and adding this entry

tmpdir=”/path/to/the/temp/directory”

  • Share/Bookmark

Retrieving nth Salary from DB

1

Category : General

This query lets you find the nth highest salaries employees.

Select * From @Table [T1] Where
(2 = (Select Count(Distinct [ESalary]) From @Table [T2] where [T1]।[ESalary] <= [T2].[ESalary]))

Replace 2 with 3,4 ,5,6 etc to get the 3,4 ,5,6 etc highest salaried employees

  • Share/Bookmark

Essential Mac Software

Category : General

  • Share/Bookmark

5 ways to optimize mysql inserts

Category : Information

 

by Justin Silverton

The following are five ways to improve queries involving table inserts:

1) use LOAD DATA INFILE when loading data from a text file

This is around 20 times faster than using insert statements.

2) use INSERT statements with multiple VALUES lists to insert several rows at a time

This is many times faster than using separate single-row insert statements. Tuning the bulk_insert_buffer_size variable can also make inserts (to tables that contain rows) even faster.

3) enable concurrent inserts for myisam tables

The concurrent_insert system variable can be set to modify the concurrent-insert processing. By default, the variable is set to 1. If concurrent_inserts is set to 0, concurrent inserts are disabled. If the variable is set to 2, concurrent inserts at the end of the table are allowed even for tables that have deleted rows.

4) use insert delayed

This is useful if you have clients that cannot or need not wait for the insert to complete. This is a common situation when you use MySQL for logging and you also periodically run select and update statements that take a long time to complete. When a client uses insert delayed, the server returns right away, and the row is queued to be inserted when the table is not in use by any other thread. Another benefit of using insert delayed is that inserts from many clients are bundled together and written in one block. This is much faster than performing many separate inserts.

5) lock your tables before inserting (for non-transactional tables)

This benefits performance because the index buffer is flushed to disk only once, after all insert statements have completed. Normally, there would be as many index buffer flushes as there are insert statements. Explicit locking statements are not needed if you can insert all rows with a single insert.

To obtain faster insertions for transactional tables, you should use start transaction and commit instead of lock tables. 

 

Reblog this post [with Zemanta]
  • Share/Bookmark

Amit Yadav is Digg proof thanks to caching by WP Super Cache