Home > database >  Like with substr and efficiency
Like with substr and efficiency

Time:09-16

If this value is in my field end_time 201908, there are hundreds of millions of data, to match the year, substr (end_time, 1, 4)=2019 and end_time like '2019%', which is more efficient, why

CodePudding user response:

First of all, in the case of no index, it is generally believed substr is better than that of the like;
Second, if there are indexed end_time fields, like use index, substr useless index, so the like is better than that of the substr;
But indexed, you can also use substr (end_time, 1, 4) to build index,
Relative merits, it still should according to the specific circumstances of test and analysis,
  • Related