GithubHelp home page GithubHelp logo

Comments (1)

GuptaManan100 avatar GuptaManan100 commented on September 25, 2024

I looked at this failure, and I know what's happening.
The plan that Vitess produces for this query is this -

{
  "OperatorType": "FkCascade",
  "Inputs": [
    {
   "InputName": "Selection",
      "OperatorType": "Route",
      "Variant": "Unsharded",
      "Keyspace": {
        "Name": "uks",
        "Sharded": false
      },
      "FieldQuery": "select fk_t11.col from fk_t11, fk_t12 where 1 != 1",
      "Query": "select fk_t11.col from fk_t11, fk_t12 where fk_t11.id = 4 and fk_t11.id = fk_t12.id for update",
      "Table": "fk_t11, fk_t12"
    },
    {
    "InputName": "CascadeChild-1",
      "OperatorType": "Delete",
      "Variant": "Unsharded",
      "Keyspace": {
        "Name": "uks",
        "Sharded": false
      },
      "TargetTabletType": "PRIMARY",
      "BvName": "fkc_vals",
      "Cols": [
        0
      ],
      "Query": "delete from fk_t12 where (col) in ::fkc_vals",
      "Table": "fk_t12"
    },
    {
    "InputName": "Parent",
      "OperatorType": "Delete",
      "Variant": "Unsharded",
      "Keyspace": {
        "Name": "uks",
        "Sharded": false
      },
      "TargetTabletType": "PRIMARY",
      "Query": "delete fk_t11 from fk_t11, fk_t12 where fk_t11.id = 4 and fk_t11.id = fk_t12.id",
      "Table": "fk_t11"
    }
  ]
}

From the outset, the plan looks fine, but when we try to see the exact order of execution, the problem becomes apparent.

The order of queries Vitess runs is this -

  1. select fk_t11.col from fk_t11, fk_t12 where fk_t11.id = 4 and fk_t11.id = fk_t12.id for update
  2. delete from fk_t12 where (col) in ::fkc_vals
  3. delete fk_t11 from fk_t11, fk_t12 where fk_t11.id = 4 and fk_t11.id = fk_t12.id

The problem is that once the 2nd query runs, (which is the cascade), the rows with id = 4 are gone from the fk_t12 table!! So now when we run the last query, there is no delete, since no row qualifies and therefore no failure!

This essentially shows up as though the delete query only ended up deleting 2 rows from fk_t12 and nothing else!

from vitess.

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.