-
Notifications
You must be signed in to change notification settings - Fork 25
Add query statistics support #215
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -877,3 +877,91 @@ FROM | |
assert!(result_set_count > 1); // ensure get multiply results | ||
Ok(()) | ||
} | ||
#[tokio::test] | ||
#[traced_test] | ||
#[ignore] // need YDB access | ||
async fn test_stats_updates() -> YdbResult<()> { | ||
let client = create_client() | ||
.await?; | ||
|
||
client | ||
.table_client() | ||
.create_session() | ||
.await? | ||
.execute_schema_query( | ||
"CREATE TABLE test_values (id Int64, vInt64 Int64, PRIMARY KEY (id))".to_string(), | ||
) | ||
.await?; | ||
|
||
|
||
let mut tx = client.table_client().create_interactive_transaction(); | ||
let res = tx.query(Query::new( | ||
"UPSERT INTO test_values (id, vInt64) VALUES (1, 2),(3,4)", | ||
).with_stats(crate::QueryStatsMode::Basic)) | ||
.await?; | ||
|
||
tx.commit().await?; | ||
|
||
println!("{:?}", res.stats); | ||
|
||
assert_eq!(2, res.stats.map(|x|x.rows_affected()).unwrap_or(0)); | ||
|
||
|
||
|
||
client | ||
.table_client() | ||
.create_session() | ||
.await? | ||
.execute_schema_query("DROP TABLE test_values".to_string()) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
#[traced_test] | ||
#[ignore] // need YDB access | ||
async fn test_stats_reads() -> YdbResult<()> { | ||
let client = create_client() | ||
.await?; | ||
|
||
client | ||
.table_client() | ||
.create_session() | ||
.await? | ||
.execute_schema_query( | ||
"CREATE TABLE test_values (id Int64, vInt64 Int64, PRIMARY KEY (id))".to_string(), | ||
) | ||
.await?; | ||
|
||
let mut tx = client.table_client().create_interactive_transaction(); | ||
let _res = tx.query(Query::new( | ||
"UPSERT INTO test_values (id, vInt64) VALUES (1, 2),(3,4)", | ||
)) | ||
.await? | ||
; | ||
|
||
|
||
|
||
|
||
let res = tx.query(Query::new("SELECT * FROM test_values") | ||
.with_stats(crate::QueryStatsMode::Basic)) | ||
.await?; | ||
|
||
tx.commit().await?; | ||
|
||
println!("{:?}", res.stats); | ||
|
||
assert_eq!(2, res.stats.map(|x|x.rows_affected()).unwrap_or(0)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason same as above: upsert delay apply until ydb need it. In the case - up to the select. And upsert really apply only on when you send select. You can select twice: upsert will be applied for first select and you will see only reads for second select. |
||
|
||
|
||
|
||
client | ||
.table_client() | ||
.create_session() | ||
.await? | ||
.execute_schema_query("DROP TABLE test_values".to_string()) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
use crate::QueryStatsMode; | ||
|
||
#[derive(serde::Serialize)] | ||
pub(crate) enum RawQueryStatMode{ | ||
pub(crate) enum RawQueryStatsMode { | ||
None, | ||
Basic, | ||
Full, | ||
Profile, | ||
} | ||
|
||
impl From<RawQueryStatMode> for ydb_grpc::ydb_proto::table::query_stats_collection::Mode { | ||
fn from(v: RawQueryStatMode) -> Self { | ||
impl From<RawQueryStatsMode> for ydb_grpc::ydb_proto::table::query_stats_collection::Mode { | ||
fn from(v: RawQueryStatsMode) -> Self { | ||
use ydb_grpc::ydb_proto::table::query_stats_collection::Mode as grpcMode; | ||
match v { | ||
RawQueryStatMode::None => grpcMode::StatsCollectionNone, | ||
RawQueryStatMode::Basic => grpcMode::StatsCollectionBasic, | ||
RawQueryStatMode::Full => grpcMode::StatsCollectionFull, | ||
RawQueryStatMode::Profile => grpcMode::StatsCollectionProfile, | ||
RawQueryStatsMode::None => grpcMode::StatsCollectionNone, | ||
RawQueryStatsMode::Basic => grpcMode::StatsCollectionBasic, | ||
RawQueryStatsMode::Full => grpcMode::StatsCollectionFull, | ||
RawQueryStatsMode::Profile => grpcMode::StatsCollectionProfile, | ||
} | ||
} | ||
} | ||
|
||
impl From<QueryStatsMode> for RawQueryStatsMode { | ||
fn from(value: QueryStatsMode) -> Self { | ||
match value { | ||
QueryStatsMode::Basic => RawQueryStatsMode::Basic, | ||
QueryStatsMode::None => RawQueryStatsMode::None, | ||
QueryStatsMode::Full => RawQueryStatsMode::Full, | ||
QueryStatsMode::Profile => RawQueryStatsMode::Profile, | ||
} | ||
} | ||
} |
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.
YDB may delay some operations, for example all changes delay up to end of transation if no need result of the update (for example read the table). Try check statistic on commit or try read same table - for force apply upsert