M
M
Maxim Vlasov2019-03-22 00:42:09
MySQL
Maxim Vlasov, 2019-03-22 00:42:09

How bad is it to use such a request?

I'm making a kind of online store on Laravel. And Eloquent offers this query option:

select * from `products` where exists (
    select `id` from `properties_values_int`
    where `products`.`id` = `properties_values_int`.`product_id` and `value` = ?
) and exists (
    select `id` from `properties_values_string`
    where `products`.`id` = `properties_values_string`.`product_id` and `value` = ?
) and exists (
    select `id` from `properties_values_string`
    where `products`.`id` = `properties_values_string`.`product_id` and `value` = ?
)

How bad is it to use such a query when filtering products, given that the property types are spread across tables and indexes are placed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Developer, 2019-03-22
@tr0yka

The answer is irrelevant without load data.
If there is no load, then this is quite a good request.
If this query is executed for a long time, but there are frequent calls to it, that data does not change there, then it makes sense to prepare a selection in advance, write the result to a separate table and give this data to users

N
Northern Lights, 2019-03-22
@php666

Do explain and see.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question