If we use a > 1 to build range in physical plan builder phase, will get (1, +∞) first, then we will get a []types.IntColumnRange like [{2, +∞}].
However, this range will call function greaterRowCount(). So the result actually is calculated as (2, +∞).
This pr is to fix this.
When we can't find a column in stats table, we return a pseudo table for now. It's not reasonable.
We should return a real table and use pseudo estimation for the missed histogram.
Currently, we use startTS of a txn as the version of a stats table. There may be an error like this:
txn1 with version 2 write firstly.
TiDB update it, and the latest udpate version is 2.
then txn2 with version 1 write.
TiDB will never get it with the version 2.
So we choose to get the table stats which version is greator than the version before last two lease.
after we support delta updae in #3053 , we shouldn't load the whole histogram when we find the table version updated. Every histogram has it's own version.
When insert and update happens, we will cache the changed info in every session. After a duration(five minutes now) passes, handle will sweep every cache and merge them. Then dump the delta info to TiKV.
Now we assume that the order of columns in stats matches the column offsets. It will return wrong stats sometimes.
If we analyze when a table is (c1, c2) and then drop c1, the c2's offset will become 0. But in stats the position of 0 is c1. I have added this case to test.
When the ddl happens after loading stats. We can estimate as peusdo column for the missed column, instead of making the whole table peusdo.
I havn't processed the case of index. It's the first step.