Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

396
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda