Effective way to keep order in mySQL for a list of items

I want to make the code cleaner and more efficient, and I wanted to know any other suggestions on the following issue:

I have a mySQL database that stores data about a set of photo names. Oh let's say 100 photo names

Table 1: (photos) has the following fields: photo_id, photo_name

Ex data:

1 | sunshine.jpg
2 | cloudy.jpg
3 | rainy.jpg
4 | hazy.jpg
...

Table 2: (categories) has the following fields: category_id, category_name, category_order

Ex data:

1 | Summer Shots | 1,2,4
2 | Winter Shots | 2,3
3 | All Seasons  | 1,2,3,4
...

Is it efficient to store the order of photos this way for each record through comma-separated values? This is one approach I've seen before, but I wanted to know if anything else was faster at runtime.

, , INNER JOIN , .

Ex: → sunshine.jpg, cloudy.jpg, hazy.jpg, 1,2,4

, O (n ^ 2), / . , :)

+3
1

, category_id, order_id photo_id

, ,

photo_id , .

- EDIT -

'photo_id', 'photo_name'

  • photo_id - , , , ,

category 'category_id', 'category_name'

  • category_id - , ( , ), , ,

table category_content 'category_id', 'photo_id', 'order'

  • category_id - , category_id
  • photo_id - , photo_id
  • - category_id
  • photo_id category_id -

"index" - MySQL, , , WHERE / JOIN , , , , -, , , , . , , , , , . ?

+6

Source: https://habr.com/ru/post/1749349/


All Articles