Answer the question
In order to leave comments, you need to log in
Is it possible to communicate anonymously on the network that satisfies the following requirements?
Is it possible to communicate on the Internet (on a certain site or outside it), in which the following principles would be observed and the requirements would be satisfied:
Answer the question
In order to leave comments, you need to log in
there are a lot of records in the products table (about 1 million)
And indexes on foreign key are constructed? A million is not enough for join to work badly.
There is only one alternative way - denormalization. All entities must be added directly to the products table in separate columns. To select only from this table.
Как уже сказали, вы не там смотрите. 1 млн — это немного, и запрос, даже с JOIN — очень простой, любая СУБД должна проглатывать его не поперхнувшись.
Скорее всего, вам надо тюнить настройки своей БД, там явно что-то не в порядке. Вот, например, статья для PostgreSQL: https://ruhighload.com/%D0%A2%D1%8E%D0%BD%D0%B8%D0...
Еще подобные статьи не раз публиковались на Хабрахабре.
Для начала надо показать здесь вывод EXPLAIN ANALYZE
запроса (или аналог для вашей СУБД).
не хотите JOIN - можете так:
select p.id, p.name
from product p
where p.model_id in (
select m.id from models m
inner join brands b on b.id = m.brand_id
inner join countries c on c.id = b.country
where
m.brand_id in () -- фильтруете бренды
and b.country in () -- фильтруете страны
and m.id in () -- фильтруете модели
)
вложенный подзапрос возвратит набор отфильтрованных model_id.
для огромной (шучу) таблици product желателен индекс по model_id.
The data uploaded by the user should be accessible only to him and to those whom he allows access to them.- nothing will save you from F12 or a screenshot.
Users in a conversation must be sure that they are communicating with the person they wanted to communicate with.- from the protocol of interrogation: "that day my sister had friends visiting, one of them could use my computer"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question