0

I have a website which stores links like website.com/picture?id=12345

I'm considering obfusicating the number-id and converting it into something like "Af3Gh2" so that people find it harder to iterate and scrape all the links

Would a Query like select * from table where row_id=12345 be faster to compute than select ... where row_id="Af3Gh2"

The row_id column is indexed already

wolfgang
  • 7,281
  • 12
  • 44
  • 72
  • 1
    possible duplicate of [SQL SELECT speed int vs varchar](http://stackoverflow.com/questions/2346920/sql-select-speed-int-vs-varchar) – inquisitive Feb 28 '15 at 08:03

1 Answers1

0

Here is the performance ranking for primary-keys from fastest to slowest auto-increment-integer > random-integer > random-char > random-varchar

There is enough material regarding why this is so. In short: Data on disk is spread in order of primary key (aka clustering). Hence random is slower than sequential. With sequential indexing when you insert a record, on disk it goes after the last record. But with random indexing, each insert needs to wedge-in between two records. On disk things take time to actually move around.

char fields are faster than varchar because chars can be read as is. But to read a varchar data you need to (1) read first byte to get the actual length. (2) read no. of chars equal to now known length.

character (char/varchar) is slower then integer because integer-integer comparison is easy. To compare two character type data, one first needs to convert them into integer, or somehow get them into lexical (dictionary) order. Mostly it is done by matching both strings character-by-character. Thus slooow.

inquisitive
  • 3,549
  • 2
  • 21
  • 47
  • Lots of misinformation here. Sequential != serial, and you can't seriously believe that the length of a VARCHAR is read in a completely separate disk operation from reading the data. – user207421 Feb 28 '15 at 08:48
  • @EJP Of course varchar operations are optimised, but context was "as compared to char". I accept possible misinformation. The sequential vs serial thing went past me. Care to enlighten? Please. – inquisitive Feb 28 '15 at 14:21