user3662467
user3662467

Reputation: 163

what to do for performance when using a slug in an url?

I see lots of websites using slugs in URLs, like these:

[catalog-product id="179"] ---> [catalog-product slug="5oz-modelling-hammer"]

I'd like to know: compared to Int search, will String search in MySQL cause performance problems?

I know about indexed fields, but I wonder whether it will cause a problem because the query is run whenever a page is visited. And what is the best practice in table design or eve what are other back-end techniques I should know about?

Upvotes: 0

Views: 446

Answers (1)

Álvaro González
Álvaro González

Reputation: 146450

This kind of question gets asked often in many forms:

  • What's faster, require or include?
  • What's faster, echo $a . $b or echo $a, $b?
  • What's faster, DATE or VARCHAR?
  • What's faster, number % 2 or number & 1?

Computers as fast enough to make the answer irrelevant. You'd need to do those operations like 1 billion times per page load to make a difference and, in that case, you'd have bigger problems. Performance bottlenecks tend to be fairly obvious:

  • Link 50MB worth of pictures in your HTML
  • Run SQL in loops and flood the DB server with hundreds of identical queries
  • Read huge XML files in memory

To sum up, whether to use IDs, slugs or both is basically a design decision that does not depend on how fast the server is.

  • Just numbers can be unacceptable for an e-commerce site that relies heavily on SEO
  • Just slugs can be unacceptable for a community driven site where the page title can be freely modified

Upvotes: 2

Related Questions