Performance test for SQL parser

Source: Internet
Author: User

For the same SQL statement, parse out the AST syntax tree using 3 parsers (this is the compiler theory, the SQL parsing may be the parser's custom statement type), performing 11 million time comparisons.

Package Demo.test;import Java.io.stringreader;import Java.sql.sqlsyntaxerrorexception;import Net.sf.jsqlparser.jsqlparserexception;import Net.sf.jsqlparser.parser.ccjsqlparser;import Net.sf.jsqlparser.parser.ccjsqlparsermanager;import Net.sf.jsqlparser.statement.statement;import Org.opencloudb.parser.sqlparserdelegate;import Com.alibaba.druid.sql.ast.sqlstatement;import Com.alibaba.druid.sql.dialect.mysql.parser.mysqlstatementparser;import Com.foundationdb.sql.parser.querytreenode;import Com.foundationdb.sql.parser.sqlparser;import Com.foundationdb.sql.parser.sqlparserfeature;public class Testparser {public static void main (string[] args) {String sql = "INSERT into employee (ID,NAME,SHARDING_ID) VALUES (5, ' WDW ', 10010)"; int count = 1000000;long start = System.currentti Memillis (); System.out.println (start), try {for (int i = 0; i < count; i++) {Sqlparser parser = new Sqlparser ();p arser.getfeatures (). Add (sqlparserfeature.double_quoted_string);p arser.getfeatures (). Add (Sqlparserfeature.mysql_hints);p arser.getfeatures (). Add (Sqlparserfeature.mysql_interval);//fix operation symbol parsing problem add by Micmiuparser.getfeatures ( ). Add (Sqlparserfeature.infix_bit_operators); Querytreenode ast =parser.parsestatement (SQL);//querytreenode ast = Sqlparserdelegate.parse (sql, "Utf-8");}} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();} Long end = System.currenttimemillis (); SYSTEM.OUT.PRINTLN (Count + "Times parse,fdb Cost:" + (End-start) + "MS"), start = end;try {for (int i = 0; I < count; i++) {//statements stmt = ccjsqlparserutil.parsestatements (sql); Statement stmt =new Ccjsqlparsermanager (). Parse (new StringReader (SQL));}} catch (Jsqlparserexception e) {//TODO auto-generated catch Blocke.printstacktrace ();} End = System.currenttimemillis (); SYSTEM.OUT.PRINTLN (Count + "Times Parse,jsqlparser Cost:" + (End-start) + "MS"); start = end;for (int i = 0; I < count; i++) {Mysqlstatementparser parser = new Mysqlstatementparser (SQL); SQLStatement statement = Parser.parsestatement ();} End = System.currenttimemillis (); SYSTEM.OUT.PRINTLN (Count + "times parse, Druid cost:" + (End-start) + "MS");}}

Output Result:

1419327695186
1000000times Parse,fdb cost:24468ms
1000000times Parse,jsqlparser cost:11469ms
1000000times Parse, Druid Cost:1454ms

- million times: Druid than Fdbparser Fast - Times, than Jsqlparser Almost 8 Times


Reference: Mycat routing new parser selection analysis and results. docx

https://github.com/MyCATApache/Mycat-doc/blob/master/Mycat%E8%B7%AF%E7%94%B1%E6%96%B0%E8%A7%A3%E6%9E%90%E5%99% A8%e9%80%89%e5%9e%8b%e5%88%86%e6%9e%90%e4%b8%8e%e7%bb%93%e6%9e%9c.docx

Performance test for SQL parser

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.