I have an suggestion regarding your second option.
If you need to keep the MyISAM tables with each unique my_column
value separated from other MyISAM tables, you may want to look into the MERGE (Mrg_MyISAM) Storage Engine as an alternative to table partitioning.
This will allow your multiple MyISAM tables within the same database that have identical table structures and index layout to be mapped together in such a way that single query hits all MyISAM tables.
Suppose you have a table as follows:
CREATE TABLE tb1
(
my_column INT NOT NULL
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(30),
PRIMARY KEY (my_column,id),
KEY name (my_column,name)
) ENGINE=MyISAM;
and you have 3 such tables (tb1, tb2, tb3) where
- my_column for tb1 = 1
- my_column for tb2 = 2
- my_column for tb3 = 3
You can merge them under a single table mapping as follows:
CREATE TABLE tbmerge LIKE tb1;
ALTER TABLE tbmerge ENGINE=Mrg_MyISAM UNION=(tb1,tb2,tb3);
To perform a search through all the tables, just use tbmerge. For example, suppose you want to see every name from tb2 that starts with 'Jack', you run this query:
SELECT name FROM tbmerge WHERE my_column=2 AND name LIKE 'Jack%';
Given the design of the table, you should always specify the value for my_column. In fact, for every index tb1 has, make sure my_column is always the first column. The reason? A query against tbmerge is always a query against tb1, tb2, tb3 (all underlying tables). Otherwise, this query
SELECT name FROM tbmerge WHERE name LIKE 'Jack%';
will experience horrible performance because it will perform table scans against all underlying tables. Please plan carefully the indexes you will be using, following that simple rule (using my_column as the first column of every index)
There is an additional benefit: You can INSERT into the underlying tables at your convenience, thus working with the
I discussed this using MERGE tables in an earlier post (Jan 4, 2012).
The best strategy for your case is to properly index the table, update statistics and defrag it. That should solve the problem.
There is no inherent limitation on row count in SQL Server. With the right indexes it should not start to become slower.
You need to look at your select and update queries and build useful indexes for them.
Best Answer
In my experiences with similar things (tables of scheduled jobs and tasks), everything is in one table. There is usually a
status
column, but jobs of all statuses are in the same table (sometimes there's an index onstatus
). As for primary key, why not just use a sequential ID? I've seen that work very well. You can also have as combined key of draft number AND actual job number, unless there's some other requirement I'm not understanding.If you think this will improve performance, make sure you have measurable problems that can only be solved this way before you make any changes. Also try to prove that this method results in actual necessary performance gains.