-
Notifications
You must be signed in to change notification settings - Fork 599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(frontend):change query_handle to return data stream #5556
Conversation
ba2e65b
to
3f22b73
Compare
Codecov Report
@@ Coverage Diff @@
## main #5556 +/- ##
==========================================
- Coverage 74.31% 74.25% -0.06%
==========================================
Files 907 907
Lines 142996 143193 +197
==========================================
+ Hits 106269 106334 +65
- Misses 36727 36859 +132
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/frontend/src/handler/query.rs
Outdated
@@ -69,10 +72,15 @@ pub async fn handle_query( | |||
}; | |||
|
|||
let rows_count = match stmt_type { | |||
StatementType::SELECT => rows.len() as i32, | |||
StatementType::SELECT => 0_i32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this is 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for query statement, rows_count is meaningless because it's stream mode. We will calculate the row count when we receive the data.
I have added the related comment in the rows_count field of PgResponse.
// row count of effected row. Used for INSERT, UPDATE, DELETE, COPY, and other statements that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better if we use Option
here.
3f22b73
to
9efe992
Compare
src/frontend/src/handler/query.rs
Outdated
@@ -29,7 +32,7 @@ use crate::scheduler::{ | |||
}; | |||
use crate::session::{OptimizerContext, SessionImpl}; | |||
|
|||
pub type QueryResultSet = Vec<Row>; | |||
pub type QueryResultSet = BoxStream<'static, std::result::Result<Row, BoxedError>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use generic to avoid this Box
? There could be millions of rows in the result set, and I'm not sure whether this impacts the performance a lot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it may impact the performance. I try to use generic but it will make so many places full of generic param. I think it's not appropriate to use generic param( at least the way I use .
I think there are other ways to solve this problem:
- use the type implement stream trait to avoid generic param
- use Vec instead of Row to decrease the time of call next()
BoxStream<'static, std::result::Result<Vec,BoxedError>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it may impact the performance.
Could you elaborate this point? 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boxstream is Box, it's a dynamic bind. So I guess every time we call 'stream.next()' to get a row, it needs to call by some mechanism like vtable. Hence if there are millions of rows in the result set, we may need to access vtable millions of times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeees, Sorry I misread it as "may not impact" 😄😄😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the type implement stream trait to avoid generic param
Yes. We may Type Alias Impl Trait here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Vec instead of Row to decrease the time of call next()
BoxStream<'static, std::result::Result<Vec,BoxedError>>
I have used this way to decrease the time of calling stream.next() .
And I will create a new PR to create a new stream type to avoid Boxstream later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please create an issue for that
src/frontend/src/handler/query.rs
Outdated
@@ -69,10 +72,15 @@ pub async fn handle_query( | |||
}; | |||
|
|||
let rows_count = match stmt_type { | |||
StatementType::SELECT => rows.len() as i32, | |||
StatementType::SELECT => 0_i32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better if we use Option
here.
8d8afe3
to
6093a37
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM
src/utils/pgwire/src/pg_response.rs
Outdated
values: Vec<Row>, | ||
row_desc: Vec<PgFieldDescriptor>, | ||
) -> Self { | ||
Self { | ||
stmt_type, | ||
row_cnt, | ||
row_cnt: row_cnt.unwrap_or(0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also change the field to Option
?
6093a37
to
5fc18fa
Compare
I hereby agree to the terms of the Singularity Data, Inc. Contributor License Agreement.
What's changed and what's your intention?
PLEASE DO NOT LEAVE THIS EMPTY !!!
change query_handle to return data stream
Checklist
./risedev check
(or alias,./risedev c
)Refer to a related PR or issue link (optional)
#5233