SHARDING-JDBC Source analysis of database sub-Library sub-table middleware--sql parsing (vi) deleting SQL

Source: Internet
Author: User
Tags mysql delete

650) this.width=650; "src=" https://www.iocoder.cn/images/common/wechat_mp_2017_07_31.jpg "style=" border:2px Solid RGB (238,238,238); margin-top:0px; "/>

Attention to the public number: "Taro Road source code" has benefits:

  1. Rocketmq/mycat/sharding-jdbc all Source analysis articles List

  2. ROCKETMQ/MYCAT/SHARDING-JDBC Chinese Note source GitHub address

  3. Your questions about the source code will be carefully replied to each message. even do not know how to read the source code can also ask Oh .

  4. new Source code parsing articles receive notifications in real time . Update one article per week .

  5. serious source of Communication Group.

This article is mainly based on SHARDING-JDBC 1.5.0 Official edition

    • 1. Overview

    • 2. Deletestatement

    • 3. #parse ()

      • 3.1 #skipBetweenDeleteAndTable ()

      • 3.2 #parseSingleTable ()

        / li>
      • 3.3 #parseWhere ()

    • 666. Easter eggs

1. Overview

Before reading this article:

    • The lexical analysis of SQL parsing (i)

    • SQL Resolution (ii) of SQL

This article shares the removal of SQL parsing source code implementation.

If you already understand SQL Resolution (c) query SQL, then this article will be a hydrology, as a kind of relaxation. As in the text above, take MySQL for example. Let's take a look at Mysqldeleteparser.

There are 2 types of MySQL DELETE syntax:

    • The first type:single-table syntax

DELETE [low_priority] [QUICK] [IGNORE] from Tbl_name [PARTITION (Partition_name,...)]    [WHERE Where_condition]    [ORDER by ...] [LIMIT Row_count]
    • second:

delete [low_priority] [quick] [ignore]    tbl_name[.*] [, tbl_ Name[.*]] ...    from table_references    [where where_ Condition] "OR" delete [low_priority] [quick] [ignore]    from tbl_name[ .*] [, tbl_name[.*]] ...    using table_references     [where where_condition] 

SHARDING-JDBC currently supports only the first type. Few of the second types of business scenarios are used.

SHARDING-JDBC Update SQL parsing main flow is as follows:

650) this.width=650; "src=" Http://www.iocoder.cn/images/Sharding-JDBC/2017_08_02/01.png "style=" border:2px Solid RGB (238,238,238); margin-top:0px; "/>

// [email protected] deletestatement parse ()  {   sqlparser.getlexer () . NextToken (); //  skip  delete   skipbetweendeleteandtable (); // //  Skip keywords, such as  low_priority, ignore , and  from   sqlparser.parsesingletable in:mysql  ( deletestatement); //  Parse table    sqlparser.skipuntil (defaultkeyword.where); //  jump to  where   sqlparser.parsewhere (deletestatement); //  analysis  WHERE    return deletestatement;} 

SHARDING-JDBC is collecting the use of the company list: Portal.
Your registration will allow more people to participate and use SHARDING-JDBC. Portal
SHARDING-JDBC will therefore be able to cover more business scenarios. Portal
Check it out, you old tart! Portal

2. Deletestatement

Delete the SQL resolution results.

Public final class Updatestatement extends Abstractsqlstatement {}

Yes, there are no other properties.

delete IGNORE from T_user WHERE user_id = parse result :

650) this.width=650; "src=" Http://www.iocoder.cn/images/Sharding-JDBC/2017_08_02/02.png "style=" border:2px Solid RGB (238,238,238); margin-top:0px; "/>

3. #parse () 3.1 #skipBetweenDeleteAndTable ()

DELETEThere are some lexical forms between and table names that have no effect on SQL routing and overrides and are skipped.

[email protected] void skipbetweendeleteandtable () {Getsqlparser (). Skipall (Mysqlkeyword.low_priority,   Mysqlkeyword.quick, Mysqlkeyword.ignore); Getsqlparser (). skipifequal (Defaultkeyword.from);}   [email protected] void skipbetweendeleteandtable () {Getsqlparser (). skipifequal (Defaultkeyword.from); Getsqlparser (). skipifequal (oraclekeyword.only);}
3.2 #parseSingleTable ()

To parse the table , see the section "SQL Resolution (ii)" of SQL resolution #parseSingleTable() .

3.3 #parseWhere ()

Parses the WHERE condition. Parse code: SQL Resolution (ii) of SQL #parsewhere () section.

666. Eggs

Friend, can you share a wave with me?

Later SQL routing and rewriting will be more interesting yo!


SHARDING-JDBC Source analysis of database sub-Library sub-table middleware--sql parsing (vi) deleting SQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.