Partition Table in MySQL
Partition Table : Partitioned tables allow your data to be broken down into smaller, more manageable pieces called partitions. Partitioning can also bring better performance, because many queries can prune (ignore) partitions that, according to the WHERE
clause, won't have the requested rows, thereby reducing the amount of data to be scanned to produce a result set. E.G. If you run a query over a million of data in case of normal table it will search for the entire table while in case of partition table it will search only at the desired partition.
Partition Table was introduced in MySQL 5.1.
There are a number of benefits that come with partitioning, but the two main advantages are:
Following is a sample SQL statement for Creating table
Create Table Statement
CREATE TABLE t3 (mobile VARCHAR(12),created_on TIMESTAMP)
PARTITION BY RANGE (UNIX_TIMESTAMP(created_on))
(PARTITION p0 VALUES LESS THAN (UNIX_TIMESTAMP('2012-06-16 00:00:00')),
PARTITION p1 VALUES LESS THAN (UNIX_TIMESTAMP('2012-07-01 00:00:00')),
PARTITION p2 VALUES LESS THAN (UNIX_TIMESTAMP('2012-07-16 00:00:00')),
PARTITION p3 VALUES LESS THAN (UNIX_TIMESTAMP('2012-08-01 00:00:00')),
PARTITION p4 VALUES LESS THAN (UNIX_TIMESTAMP('2012-08-16 00:00:00')),
PARTITION p5 VALUES LESS THAN (UNIX_TIMESTAMP('2012-09-01 00:00:00')),
PARTITION p6 VALUES LESS THAN (UNIX_TIMESTAMP('2012-09-16 00:00:00')),
PARTITION p7 VALUES LESS THAN (UNIX_TIMESTAMP('2012-10-01 00:00:00')),
PARTITION p8 VALUES LESS THAN (UNIX_TIMESTAMP('2012-10-16 00:00:00')),
PARTITION p9 VALUES LESS THAN (UNIX_TIMESTAMP('2012-11-01 00:00:00')),
PARTITION p10 VALUES LESS THAN (UNIX_TIMESTAMP('2012-11-16 00:00:00')),
PARTITION p11 VALUES LESS THAN (UNIX_TIMESTAMP('2012-12-01 00:00:00')),
PARTITION p12 VALUES LESS THAN (UNIX_TIMESTAMP('2012-12-16 00:00:00')),
PARTITION p13 VALUES LESS THAN (UNIX_TIMESTAMP('2013-01-01 00:00:00')),
PARTITION p14 VALUES LESS THAN MAXVALUE
);
Insert Statement
INSERT INTO t2 VALUES('919971114501','2013-10-22 10:20:05');
Drop a Partition
ALTER TABLE t3 DROP PARTITION p5;
Refer the Following URL to know more about partitioning : http://dev.mysql.com/tech-resources/articles/partitioning.html
http://www.rcramer.com/tech/sql/mysql_partition.html
What are HEAP tables in MySQL?
HEAP tables are in-memory. They are usually used for high-speed temporary storage. No TEXT or BLOB fields are allowed within HEAP tables. You can only use the comparison operators = and <=>. HEAP tables do not support AUTO_INCREMENT. Indexes must be NOT NULL
e.g. Create table test(num int) Engine=Memory;
Default time set in MySQL Tables during Create Table.
CREATE TABLE TEST
(
num int(10),
trndate TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)
);
Default time set in MySQL Tables during Create Table.
CREATE TABLE TEST
(
num int(10),
trndate TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)
);
How to Create Data files and index files in different diskspace in MySQL?
Create table test(i int) data directory '/home/sandip/data',index directory '/home/sandip/index';
Default time set in MySQL Tables during Create Table.
CREATE TABLE TEST
( num int(10),
trndate TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)
);
What are HEAP tables in MySQL?
HEAP tables are in-memory. They are usually used for high-speed temporary storage. No TEXT or BLOB fields are allowed within HEAP tables. You can only use the comparison operators = and <=>. HEAP tables do not support AUTO_INCREMENT. Indexes must be NOT NULL
e.g. Create table test(num int) Engine=Memory;
What are CSV tables?
Those are the special tables, data for which is saved into comma-separated values files. They cannot be indexed.
e.g. Create table test (i int not null, c char(10) not null) Engine=CSV;
Insert into test values (1,'recordone'),(2,'recordtwo'),(3,'recordthree');
select * from test;
Explain federated tables.
Introduced in MySQL 5.0, federated tables allow access to the tables located on other databases on other servers.
ENGINE=FEDERATED
DEFAULTCHARSET=latin1
CONNECTION='mysql://feduser@remote_host:3306/federated/test_table;
Enum Tables with SET data datatype.
CREATE TABLE India
(
city SET('Delhi','Mumbai','Kolkata','Bangalore')
);
MERGE TABLE IN MYSQL
CREATE TABLE t1 (
-> a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> message CHAR(20)) ENGINE=MyISAM;
mysql> CREATE TABLE t2 (
-> a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> message CHAR(20)) ENGINE=MyISAM;
mysql> INSERT INTO t1 (message) VALUES ('Testing'),('table'),('t1');
mysql> INSERT INTO t2 (message) VALUES ('Testing'),('table'),('t2');
mysql> CREATE TABLE total (
-> a INT NOT NULL AUTO_INCREMENT,
-> message CHAR(20), INDEX(a))
-> ENGINE=MERGE UNION=(t1,t2) INSERT_METHOD=LAST;