GithubHelp home page GithubHelp logo

Comments (2)

zanmato1984 avatar zanmato1984 commented on August 16, 2024 1

MySQL's right shift supports two types: bigint and binary [1]. So no casting is applied to t2.a >> 8 and it evaluates to a binary as well. Whereas TiDB so far only supports bigint for right shift [2], this is why an implicit cast to bigint is applied to t2.a and this cast evaluates to 0 (with warning saying truncation). Then t2.a >> 8 still evaluates to a bigint 0. Then it is compared with binary (t3.a), causing both sides being casted to double, and the comparison is true for 0 and 0.

[1] https://dev.mysql.com/doc/refman/8.4/en/bit-functions.html#operator_right-shift
[2]

func (b *builtinRightShiftSig) evalInt(ctx EvalContext, row chunk.Row) (int64, bool, error) {

from tidb.

wengsy150943 avatar wengsy150943 commented on August 16, 2024

We explain the execution plan. It seems that TiDB will cast blob into other types before right shift, which applies incorrect truncation.

explain select * from t2,t3 where (t2.a >> 8) = t3.a;
+------------------------------+---------+-----------+---------------+---------------------------------------------------------------------------------------------------------+
| id                           | estRows | task      | access object | operator info                                                                                           |
+------------------------------+---------+-----------+---------------+---------------------------------------------------------------------------------------------------------+
| HashJoin_12                  | 1.00    | root      |               | inner join, equal:[eq(Column#5, Column#6)]                                                              |
| ├─Projection_17(Build)       | 1.00    | root      |               | test.t3.a, cast(test.t3.a, double BINARY)->Column#6                                                     |
| │ └─TableReader_19           | 1.00    | root      |               | data:TableFullScan_18                                                                                   |
| │   └─TableFullScan_18       | 1.00    | cop[tikv] | table:t3      | keep order:false, stats:pseudo                                                                          |
| └─Projection_14(Probe)       | 1.00    | root      |               | test.t2.a, cast(rightshift(cast(test.t2.a, bigint(65535) BINARY), 8), double UNSIGNED BINARY)->Column#5 |
|   └─TableReader_16           | 1.00    | root      |               | data:TableFullScan_15                                                                                   |
|     └─TableFullScan_15       | 1.00    | cop[tikv] | table:t2      | keep order:false, stats:pseudo                                                                          |
+------------------------------+---------+-----------+---------------+---------------------------------------------------------------------------------------------------------+

from tidb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.