1. mysql 之count(*)原理
select count(*) from table group by floor(rand()*2);
sql表:table
id | value |
---|---|
0 | 1 |
0 | 1 |
1 | 1 |
2 | 2 |
2 | 2 |
3 | 2 |
查询前mysql会建议一个虚拟表,查询表中第一行数据时,会insert floor(rand()*2),假如是0,查询虚拟表,发现不存在,则会再次执行floor(rand()*2),结果为1,插入虚表,这是第一条记录。
虚表(第1次查询)
id | value |
---|---|
1 | 1 |
继续第二次查询,再次计算floor(rand()*2),发现为1,此时虚表中已经存在1,所以不会再次执行floor(rand()*2)
虚表(第2次查询)
id | value |
---|---|
1 | 2 |
继续第二次查询,计算floor(rand()*2),发现为0,此时虚表中已经不存在0,所以会再次执行floor(rand()*2),
- 假如计算为0,则可以正常插入
虚表(第3次查询)
id | value |
---|---|
1 | 2 |
0 | 1 |
- 假如为1,则会报错,因为重复了。
error info: Duplicate entry '1' for key '<group_key>'
floor(rand()*2)是不可测的。
2. 注入
公式:
select count(*),floor(rand()*2)x from information_schema.tables group by x;
# floor(rand()*2)x === floor(rand()*2) as x
报错函数
updatexml函数:
or udatexml(1concat(0x7e,(version())),0)
exp()
<>
regexp
like
实际使用
username updatexml
password (params)