HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

How much will using a varchar(15) PK affect my tables performance?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
tablesmuchvarcharaffectwillusingperformancehow

Problem

I am parsing log file lines from a legacy, proprietary application into a nice easy to query DB. The log lines have no unique integer ID. They do have a UNIX timestamp as an 8 character hex string. Sadly, these timestamps are not always guaranteed to be unique. There is also a 2-6 (thus the VARCHAR) character hex ID which, when appended to the timestamp, is unique. I tested this out with ~400k records and just doing a SELECT * on the table takes over 15 seconds.

Before I go completely redesigning my table in some drastic way, I want to be sure that using this PK (as opposed to an auto-incrementing INT) is where my performance hit is. I have never really worked on a table using something other than a regular INT PK (I am a developer, not a DBA).

I am using InnoDB engine and a few FK relations to some small tables. MySQL admin is showing the data length of the table at ~150MB, and the index length at 21MB with 380k rows.

As I said, I'm a developer, not a DBA, but in my current situation I don't really have one I can bring in. I did some Googling but found a pretty wide array of answers that often delved into topics that just raised more questions for me. I'm hoping someone here can give a concise answer or at least point me to some more resources.

EDIT: Changed the column to CHAR(14) and removed one large TEXT column that was somewhat superfluous. This seems to have improved the time a good deal and took the table size down to about 80MB, but I'm still looking for suggestions.

Solution

I don't know that the PK is your issue. To me, doing a request for all 400k rows, 15 seconds doesn't sound too bad. PKs and indexes really come into the equation when you're trying to filter the set (using WHERE conditionals).

Context

StackExchange Database Administrators Q#2562, answer score: 7

Revisions (0)

No revisions yet.