You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "FakeKotaro (via GitHub)" <gi...@apache.org> on 2023/04/17 07:17:11 UTC

[GitHub] [shardingsphere] FakeKotaro opened a new issue, #25192: Some questions about SQL parsing cache

FakeKotaro opened a new issue, #25192:
URL: https://github.com/apache/shardingsphere/issues/25192

   I've been using Sharding-JDBC's encryption feature and have recently been working on SQL parsing and rewriting performance. In version 4.1.0, SQL parsing has only one layer of cache, the structure is <sql, SqlStatement>
   ```java
   private SQLStatement parse0(final String sql, final boolean useCache) {
           if (useCache) {
               Optional<SQLStatement> cachedSQLStatement = cache.getSQLStatement(sql);
               if (cachedSQLStatement.isPresent()) {
                   return cachedSQLStatement.get();
               }
           }
           ParseTree parseTree = new SQLParserExecutor(databaseTypeName, sql).execute().getRootNode();
           SQLStatement result = (SQLStatement) ParseTreeVisitorFactory.newInstance(databaseTypeName, VisitorRule.valueOf(parseTree.getClass())).visit(parseTree);
           if (useCache) {
               cache.put(sql, result);
           }
           return result;
       }
   ```
   In the new version, a separate layer of caching has been added for parsing: <sql, ParseASTNode>.
   ```java
   public ParseASTNode parse(final String sql, final boolean useCache) {
           return useCache ? parseTreeCache.get(sql) : sqlParserExecutor.parse(sql);
       }
   ```
   My question is:
   1. Why add a separate layer of caching for parsing
   2. Why not add a layer of caching for rewrites, structured as <originSql, rewrittenSql>. Taking the encryption function as an example, the cache is < "SELECT name FROM user","SELECT name_encode as name FROM user">, so that the cache can be queried when the original SQL statement is received, and there is no need to go through the process of parsing and visiting
   3. I found that the first execution of SQL statements is slow, some complex SQL in local tests even reached 100ms latency, is this normal or is there a way to speed up the first execution?
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] tuichenchuxin commented on issue #25192: Some questions about SQL parsing cache

Posted by "tuichenchuxin (via GitHub)" <gi...@apache.org>.
tuichenchuxin commented on issue #25192:
URL: https://github.com/apache/shardingsphere/issues/25192#issuecomment-1515602969

   The first execution requires parsing and is indeed slightly slower. The main slow point is parsing, so only caching is added for parsing.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org