"Obviously, when using UNION ALL, you simply combine the various queries together without judging whether the data is repeated. Therefore, when you are sure that there will be no duplicate data in the query results or that there is no need to remove duplicate data, you should Use UNION ALL to improve query efficiency.”
For the database, 24 requests will definitely consume more resources than one request (multiple verification parsing + network transmission), and if your time is continuous, you can merge it. In the worst case, union all is better if the time is not continuous. Of course, the premise is The time field has an index. It is not recommended to change it to or, because or will increase the parsing and there will be a risk of full table scan when there are too many time ranges, while union all only needs to merge the result sets
"Obviously, when using UNION ALL, you simply combine the various queries together without judging whether the data is repeated. Therefore, when you are sure that there will be no duplicate data in the query results or that there is no need to remove duplicate data, you should Use UNION ALL to improve query efficiency.”
Why not use
OR
to connect these conditions? For example:For the database, 24 requests will definitely consume more resources than one request (multiple verification parsing + network transmission), and if your time is continuous, you can merge it. In the worst case, union all is better if the time is not continuous. Of course, the premise is The time field has an index. It is not recommended to change it to or, because or will increase the parsing and there will be a risk of full table scan when there are too many time ranges, while union all only needs to merge the result sets