E
E
exactly the most2017-12-15 23:56:56
MySQL
exactly the most, 2017-12-15 23:56:56

How to properly organize the database for the Gallery?

Good day. I have a question. I need to optimize a query with a selection of values ​​by limit.
or a hint on how to design a BASE. In order to be able to write down the text for the event and photos for the event.
This is needed to insert all cards for a specific evrnt_id AND split the output into pages.
Input data.
CREATE TABLE `SRC`(
`id` INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY UNIQUE ,
`event_id` int(10) NOT NULL ,
`src` VARCHAR(55) NOT NULL ,
`alternate` VARCHAR(20) NOT NULL,
FOREIGN KEY (event_id) REFERENCES TEXTS(id)
)ENGINE = MyISAM DEFAULT CHARSET =utf8 COLLATE = utf8_unicode_ci;
CREATE TABLE `TEXTS`(
`id` INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY UNIQUE ,
`big_text` VARCHAR(200) NOT NULL ,
`small_text` VARCHAR(80) NOT NULL ,
`datetime` DATETIME NOT NULL
)ENGINE = MyISAM DEFAULT CHARSET =utf8 COLLATE = utf8_unicode_ci;
To these tables, a query of this kind.
SELECT t.id,s.src,s.alternate,t.small_text,t.datetime FROM TEXTS as t
INNER JOIN SRC s ON s.event_id=t.id
INNER JOIN (SELECT id FROM TEXTS ORDER BY id LIMIT 3 OFFSET 14 ) t2
ON t.id=t2.id;
5a34361783e70204874293.png
Here is query number 2
SELECT t.id,s.src,s.alternate,t.small_text,t.datetime FROM TEXTS as t
INNER JOIN SRC s ON s.event_id=t.id WHERE event_id=3;
here is his EPLAIN
5a34362bd31f8615930152.png
Is it necessary to make a 3rd table or can you do it this way and how to speed up the query.
Here is the actual question itself, how to ensure that 17 lines are not read and everything that is needed is displayed, but it is output specifically from the 14th id of the TEXTS table. In general, speed up the request, but what would be the division by 3 event_id.
Probably here business in the organization of basis council is necessary. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question