This is a discussion on varchar(8) but want to group by only first 4 within the MySQL Database forums, part of the Database Forums category; I have database table with varchar(8) column that is not key. It has value for example axF12b!h, axF17F!...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have database table with varchar(8) column that is not key. It has
value for example axF12b!h, axF17F!h, axF12893, etc... axF1 is always the same and I want to goup by this so I can count. How to do this? I have more than 3 million record. This is not index key. Will this be too slow and mysql timeout? |
|
|||
|
moleskyca1@yahoo.com wrote: > I have database table with varchar(8) column that is not key. It has > value for example axF12b!h, axF17F!h, axF12893, etc... > > axF1 is always the same and I want to goup by this so I can count. How > to do this? > > I have more than 3 million record. This is not index key. Will this be > too slow and mysql timeout? SELECT substr( column_name FROM 1 FOR 4 ) AS alias_name FROM table_name GROUP BY alias_name on 3 million records it can be slow - can't you add some other limitations to reduce number of rows to group?? or split it to parts?? |
|
|||
|
moleskyca1@yahoo.com wrote:
> I have database table with varchar(8) column that is not key. It has > value for example axF12b!h, axF17F!h, axF12893, etc... > > axF1 is always the same and I want to goup by this so I can count. How > to do this? > > I have more than 3 million record. This is not index key. Will this be > too slow and mysql timeout? > Yes, it will be slow. The fact you don't have an index on this column means MySQL will need to do a table scan. And the fact you're doing a string vs. integer comparison means it will be even slower. Adding an index for the column should help. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
> Adding an index for the column should help.
And you can give a string length with the index, so is you want to group on the first 4 characters, you can try to add an index with length 4. If this does not speed up the query, you might try the FORCE clause to force MySQL using that index, or else the HANDLER statement. Good luck. |