Hi Kylin team,
I found an issue while server side PreparedStatement enabled. The second time query and after's result will be different from the first when query TopN, and the result is not right.
Part of Cube info:
TOPN(PRICE) Group By:KYLIN_SALES.SELLER_ID,KYLIN_SALES.BUYER_ID
The First query result:
The Second and after:
Cached preparedContext is changed when doing preparedStatement.executeQuery, and losing groupByColumns. So the first execution result is correct, the second and the after will be incorrect.
The first time we entered PreparedStatement logic, we'll try to borrow preparedContext from cache pool, of course there isn't any, but the cache pool will execute create method to create a new preparedContext, and then loaned it to us.
I didn't figure out how adjustSqlDigest works before, and try to remove code
but it's not right. Top-N isn't like some other measures, the dimensions aren't as part of row key, they stored in measures in design, so it's why the adjustSqlDigest matters, especially those codes.
The root cause for this issue is because the create sql digest is execute again after we store it in cache, so the digest changed.
So the second time and after we execute the same query or same pattern, the expression will be changed to SUM instead of TOPN, that's why the strange result show up.