简体   繁体   中英

Mysql database efficient index structure for a large number of photos to decrease page load time and to reduce the number of select queries

Assume that we have 20,000 pages on a domain, and each page contains between 1 to 50 uploaded photos. In our case, we can have between 20,000 to 1,000,000 photos URLs on our server. The figures (a) and (b) show the schematic illustrations of index tables to connect the photos URLs to each page. Figure (a), separates the index tables based on the number of photos in each page (this structure requires more PHP coding to select the index table) and figure (b) depicts the index structure of pages based on the maximum number of photos in each page. Which of the below index structures is more efficient for a large number of photos and a MySQL database? In short, my goal is reduce the number of select queries whenever a page is requested by a user.

在此处输入图片说明

在此处输入图片说明

I'm no expert, but how about two tables

1 Table called websites with columns:

websiteid  (auto increment)
website

1 table called pictures with columns:

pictureid  (auto increment)
websiteid
field
photo_url

then you add one row per picture to the picture table

then you do a query like

select pictureid, field, photo_url from pictures where websiteid = '123'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM