net.sf.jsqlparser.parser.ParseException
sql: select count(id) from p_custom_data ignore index(pri) where tenant_id=28257 and entity_id=92609 and delete_flg=0 " + "and ( (dbc_relation_2 = 52701) and (dbc_relation_2 in ( select id from a_order where tenant_id = 28257 and 1=1 ) ) ) order by id desc, id desc
why can't parse the sql.
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered " <S_CHAR_LITERAL> "'index' "" at line 1, column 44.
Was expecting one of:
at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:5530)
at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:5406)
at net.sf.jsqlparser.parser.CCJSqlParser.Statement(CCJSqlParser.java:149)
at net.sf.jsqlparser.parser.CCJSqlParserManager.parse(CCJSqlParserManager.java:38)
... 25 more
who can answer me?
We are still on the start to provide optimizer hints. The problem here seems to be at the first glance: ignore index(pri).
this SQL statement can be executed directly by Mysql, why jsqlparse can not parse it?
because JSqlParser supports a subset of all different SQL grammars. Niche cases, like yours, have only been added slowly by other people via PRs.
It seems from the grammar that ignore index(blah) should be supported:
{
(actionToken = <K_USE>
| actionToken = <K_IGNORE>
| actionToken = <K_FORCE> )
(indexToken = <K_INDEX>
| indexToken = <K_KEY>)
"("
indexName = Identifier() { indexNameList.add(indexName); }
("," indexName= Identifier() { indexNameList.add(indexName); })*
")"
{
return new MySQLIndexHint(actionToken.image, indexToken.image, indexNameList);
}
}
And the Plain select ends up calling FromItem, which has the code for trying to find the hint
I think your best bet would be to try to use the Visualize Parsing section to see what token didn't get consumed properly.
@AnEmortalKid Thx for pointing that out. I will look into it.
Sorry for being a little late. Which version do you use? Using JSqlParser V1.1 I was able to parse your statement successfully.
Could be an older version, looks like this was fixed recently: https://github.com/JSQLParser/JSqlParser/pull/429