mysql - 24 consecutive sql statements, check one by one, is it better to union all?
滿天的星座
滿天的星座 2017-06-08 11:03:29
0
3
844

These 24 consecutive items are similar, but the conditions are different, such as 9 o'clock to 10 o'clock, 10 o'clock to 11 o'clock

滿天的星座
滿天的星座

reply all (3)
学霸

"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.”

    学习ing

    Why not useORto connect these conditions? For example:

    SELECT ... WHERE hour BETWEEN (9, 11) OR hour BETWEEN (13, 15)
      为情所困

      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

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!