You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "walterddr (via GitHub)" <gi...@apache.org> on 2024/01/22 17:29:47 UTC

[I] [multistage] attach default limit 10 to queries that doesn't have a limit [pinot]

walterddr opened a new issue, #12304:
URL: https://github.com/apache/pinot/issues/12304

   - to prevent expensive queries from potentially killing the broker if we do not apply this by default. 
   - we also need a way to explicitly warn the user the query result is default limited as a warning flag


-- 
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: commits-unsubscribe@pinot.apache.org.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [I] [multistage] attach default limit 10 to queries that doesn't have a limit [pinot]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #12304:
URL: https://github.com/apache/pinot/issues/12304#issuecomment-5786774726

   This issue has been closed because it has been inactive for 180 days. If you believe this issue is still relevant, please feel free to reopen it or create a new issue. Thank you!


-- 
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: commits-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [I] [multistage] attach default limit 10 to queries that doesn't have a limit [pinot]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed issue #12304: [multistage] attach default limit 10 to queries that doesn't have a limit
URL: https://github.com/apache/pinot/issues/12304


-- 
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: commits-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [I] [multistage] attach default limit 10 to queries that doesn't have a limit [pinot]

Posted by "dttung2905 (via GitHub)" <gi...@apache.org>.
dttung2905 commented on issue #12304:
URL: https://github.com/apache/pinot/issues/12304#issuecomment-1922563716

   Hi @walterddr,
   
   I'm just following the issue and I think applying the limit by default is a really good idea too. Although I'm quite new to the pinot code base, I think the starting point is the `setLimit()` method https://github.com/apache/pinot/blob/0a4398634be81cdbbe891b3da249134ef98743e7/pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java#L495-L499 
   I have a question. How do we know if the `LIMIT` is set in the main query or the sub query as we only want to set default limit to the main query. Could you point me to the right place in the code base ?
   I think I found the place where we parse the subquery but not sure how they all are connected
   https://github.com/apache/pinot/blob/0a4398634be81cdbbe891b3da249134ef98743e7/pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java#L510-L519
   
   Would love to create a PR to solve this if you permit :smile: 


-- 
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: commits-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [I] [multistage] attach default limit 10 to queries that doesn't have a limit [pinot]

Posted by "walterddr (via GitHub)" <gi...@apache.org>.
walterddr commented on issue #12304:
URL: https://github.com/apache/pinot/issues/12304#issuecomment-1925435872

   this will work only in happy-path. it is not guarantee that the validated top is a always SqlSelect for normal queries. but it is a good starting point. ( for example it could be a SqlSetOperator if the top is a UNION )
   i would suggest try out a whole bunch of queries and see if there's any query patterns that could evade these assumption (those could be a good test cases to be added)
   
   
   
   


-- 
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: commits-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [I] [multistage] attach default limit 10 to queries that doesn't have a limit [pinot]

Posted by "dttung2905 (via GitHub)" <gi...@apache.org>.
dttung2905 commented on issue #12304:
URL: https://github.com/apache/pinot/issues/12304#issuecomment-1924884957

   Thanks @walterddr for the detailed pointer.
   I take a look at the code and I think `validate` stage might be a good place to implement that check, something like 
   ```java
     private SqlNode validate(SqlNode parsed, PlannerContext plannerContext)
         throws Exception {
       // 2. validator to validate.
       SqlNode validated = plannerContext.getValidator().validate(parsed);
       // Check for LIMIT clause in the main query
       if (validated instanceof SqlSelect) {
         SqlSelect sqlSelect = (SqlSelect) validated;
         if (sqlSelect.getFetch() == null) {
           // Add LIMIT 100 clause 
           SqlParserPos originalPos = sqlSelect.getParserPosition();
           SqlNode limitNode = SqlLiteral.createExactNumeric("100", originalPos);
           ((SqlSelect) validated).setFetch(limitNode);
         }
       }
       if (null == validated || !validated.getKind().belongsTo(SqlKind.QUERY)) {
         throw new IllegalArgumentException(
             String.format("unsupported SQL query, cannot validate out a valid sql from:\n%s", parsed));
       }
       return validated;
     ```
   What do you think about this? Not sure if there are other places to change ( probably change test cases too )


-- 
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: commits-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [I] [multistage] attach default limit 10 to queries that doesn't have a limit [pinot]

Posted by "guzzijones (via GitHub)" <gi...@apache.org>.
guzzijones commented on issue #12304:
URL: https://github.com/apache/pinot/issues/12304#issuecomment-2603286496

   idea of limiting a query to 10 records by default is flawed.  
   
   1.  A user who runs a query without a limit may not know there are more records.
   2.  A user who runs a query setting the limit may also not know there are more records.  
   
   In the end users bypass this by:
   1. setting some unusually high arbitrary limit and hope that the record count never exceeds it
   2. run 2 queries for a query.  
       1. first count the records 
       2. run the query originally requested with `limit [record count]` set
   
   the second option of course gets more complicated with window functions, group by , etc.


-- 
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: commits-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [I] [multistage] attach default limit 10 to queries that doesn't have a limit [pinot]

Posted by "walterddr (via GitHub)" <gi...@apache.org>.
walterddr commented on issue #12304:
URL: https://github.com/apache/pinot/issues/12304#issuecomment-1922815466

   Hi @dttung2905 thank you for the interest. 
   
   yes this is indeed a relatively good beginner task to get to know the pinot codebase.
   
   a bit of a explanation: the code you linked are for the v1 engine not for the multi-stage engine. (e.g. the function you linked is to convert `SqlNode` into `PinotQuery`. In order to achieve similar effect in the multi-stage engine:
   
   1. look for where both engine utilize the same logic to parse the SQL string into `SqlNodeAndOptions`
   https://github.com/apache/pinot/blob/0a4398634be81cdbbe891b3da249134ef98743e7/pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/MultiStageBrokerRequestHandler.java#L105-L115
   
   2. look for where the query is being converted into an execution plan (`compileQuery` method)
   https://github.com/apache/pinot/blob/0a4398634be81cdbbe891b3da249134ef98743e7/pinot-query-planner/src/main/java/org/apache/pinot/query/QueryEnvironment.java#L144-L148
   
   3. you can see that the compilation runs several steps including validation, relational planning and optimizer. any one of these steps can be used to check the fetch limit 
   
   If this is too complicated, please feel free to check in again 
   (i added the beginner task tag but decided to remove it as it is not as straightforward as I original thought of)
   


-- 
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: commits-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [I] [multistage] attach default limit 10 to queries that doesn't have a limit [pinot]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #12304:
URL: https://github.com/apache/pinot/issues/12304#issuecomment-5321772307

   This issue has been automatically marked as stale because it has not had any activity in the last 150 days. It will be closed in 30 days if no further activity occurs. If this issue is still relevant, please leave a comment to keep it open. Thank you for your contributions!


-- 
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: commits-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org