Ron,
If possible it would be worth switching the data type over to a date field. The relative merits are:
Pros:
1. DBMS engine is doing the work in limiting your selects.
2. Correct indexing on the date field should produce much quicker query.
3. Your memory consumption is likely to be much lower as PHP doesn't need to build a large array and then sort it.
Cons:
1. It's a fairly substantial change.
2. Any pages that refer to this field will need to be checked.
3. You will need to stop any info going into the database in the period that you make these changes to ensure consistency.
FYI, I've just recreated your situation with a database that I have of 2.2 million entries. The timings are:
- Create new dummy column with column type date ~1.5 mins
- Update the 2.2 million rows ~ 4 - 5 mins.
- Drop the old column ~3 mins
- Rename the dummy column: ~2 mins.
You will need to set some time aside for analysing the table up to date. Also, if you have any indexes on your varchar field, it's worth droping them before you do this operation.
The update statement I used is :
update staff2 set date_2 = concat_ws('-',right(trim(date_1),2), mid(trim(date_1),4,2),left(trim(date_1),2) )
Date_1 is the varchar, date_2 the date field.
Hardware used:
AMD 800 Duron, 640Mg Ram, 10Gb disk partition, Mysql running in default setup.
All good food for thought.
CHeers
Justin