Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

394
Views
What is the optimal size of a prefix index for urls (MySQL)

I'm collecting a few million rows of data containing URLs. To deduplicate these, I need to search for an existing URL before inserting a new row. Hence, I would like to create an index on that column.

What is the best prefix size, knowing that most URLs start with http:// or https://?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

For a few million rows, there is essentially no chance that MD5(URL) will have an accidental collision. That's a 32 hex digits (CHAR(32) CHARACTER SET ascii). Or better would be UNHEX(...) and put it in BINARY(16).

Then add a UNIQUE index on that column.

What version are you using? Some newer version of MariaDB has something like that builtin.

over 4 years ago · Santiago Trujillo Report

0

The are two ways to add index on long string:

  1. add index for crc32(urls),just add a column named crc32_urls and create a index on this.It is possible some urls have same result by crc32(urls),so every time you search you should run like this:
SELECT * FROM table WHERE crc32_urls = xxx AND urls = xxx
  1. use prefix index.For assuming how much prefix's length should be.You can caculate by
SELECT COUNT(DISTINCT urls)/COUNT(*) FROM table

compared with

SELECT COUNT(DISTINCT left(urls, x))/COUNT(*) FROM table

the x is length you specified.When two number is close,choose min length.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!