In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "the calling mode of the MySQL layer comparison function". In the daily operation, I believe that many people have doubts about the calling mode of the MySQL layer comparison function. The editor consulted all kinds of data and sorted out the simple and easy-to-use operation method. I hope it will be helpful to answer the doubt of "the calling mode of the MySQL layer comparison function". Next, please follow the editor to study!
I. the source of the problem
A recent problem with date comparison is as follows:
Root@localhost:test:10:25:48 > select from_unixtime (1596680255) +-- + | from_unixtime (1596680255) | +-- + | 2020-08-06 10:17:35 | +-- + 1 row in set (1596680255 sec) root@localhost:test:10:25:52 > select from_unixtime (1596680255) '% YMMI% mMMI% d')
< '2020-08-1';+----------------------------------------------------+| from_unixtime(1596680255,'%Y-%m-%d') < '2020-08-1' |+----------------------------------------------------+| 1 |+----------------------------------------------------+1 row in set (2.70 sec)root@localhost:test:10:25:59>Select from_unixtime (1596680255)
< '2020-08-1';+-----------------------------------------+| from_unixtime(1596680255) < '2020-08-1' |+-----------------------------------------+| 0 |+-----------------------------------------+1 row in set (2.36 sec) 按理来说from_unixtime(1596680255,'%Y-%m-%d') < '2020-08-1' 应该是false才对,但是返回为true,因此怀疑为字符串比较的方式 二、问题验证 首先关闭gtid通过create table as 来验证一下字段类型如下: create table testit951asselect from_unixtime(1596678161,'%Y-%m-%d') as "tt"create table testit952asselect from_unixtime(1596678161) as "tt" 通过这种方式发现两种建表字段为varchar和datetime类型。通过源码验证可以看到如下: Breakpoint 5, Arg_comparator::compare_string (this=0x7fffe40167c0) at /cdh/mysqldebug/percona-server-5.7.29-32/sql/item_cmpfunc.cc:16721672 if ((res1= (*a)->Val_str (& value1)) (gdb) cContinuing.Breakpoint 4, Arg_comparator::compare_datetime (this=0x7fffe40164c8) at / cdh/mysqldebug/percona-server-5.7.29-32/sql/item_cmpfunc.cc:15091509 THD * thd= current_thd; (gdb) cContinuing.
You can see that string and datetime are used to compare internally. So it was proved. Finally, leave the position of the comparison function:
Item_cmpfunc.cc
At this point, on the "MySQL layer comparison function call mode" study is over, I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.