You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
5.[Retry helpers for `YDB``database/sql` driver](#retry)
16
18
*[Over `sql.Conn` object](#retry-conn)
17
19
*[Over `sql.Tx`](#retry-tx)
18
20
6.[Query args types](#arg-types)
19
21
7.[Get native driver from `*sql.DB`](#unwrap)
20
-
8.[Logging SDK's events](#logs)
21
-
9.[Add metrics about SDK's events](#metrics)
22
-
10.[Add `Jaeger` traces about driver events](#jaeger)
23
22
24
23
## Initialization of `database/sql` driver <aname="init"></a>
25
24
@@ -48,7 +47,8 @@ func main() {
48
47
db:= sql.OpenDB(connector)
49
48
}
50
49
```
51
-
### Configure driver only with data source name (connection string) <aname="init-dsn"></a>
50
+
51
+
### Configure driver with data source name or connection string <aname="init-dsn"></a>
52
52
```go
53
53
import (
54
54
"database/sql"
@@ -65,23 +65,24 @@ Data source name parameters:
65
65
* static credentials with authority part of URI, like `grpcs://root:password@localhost:2135/local`
66
66
*`query_mode=scripting` - you can redefine default [DML](https://en.wikipedia.org/wiki/Data_manipulation_language) query mode
67
67
68
-
## About session pool <aname="session-pool"></a>
68
+
## Session pooling <aname="session-pool"></a>
69
69
70
-
Native driver `ydb-go-sdk/v3` implements internal session pool, which uses with `db.Table().Do()` or `db.Table().DoTx()` methods.
71
-
Internal session pool configures with options like `ydb.WithSessionPoolSizeLimit()` and other.
72
-
Unlike session pool in native driver, `database/sql` contains another session pool, which configures with `*sql.DB.SetMaxOpenConns` and `*sql.DB.SetMaxIdleConns`.
73
-
Lifetime of `YDB` session depends on driver configuration and predefined errors, such as `sql.driver.ErrBadConn`.
74
-
`YDB` driver for `database/sql` transform internal `YDB` errors into `sql.driver.ErrBadConn` depending on result of internal error check (delete session on error or not and other).
75
-
In most cases this behaviour of `database/sql` driver implementation for specific RDBMS completes queries without result errors.
76
-
But some errors on unfortunate cases may be get on client-side.
77
-
That's why querying must be wrapped with retry helpers, such as `retry.Do` or `retry.DoTx` (see more about retry helpers in [retry section](#retry)).
70
+
Native driver `ydb-go-sdk/v3` implements the internal session pool, which uses with `db.Table().Do()` or `db.Table().DoTx()` methods.
71
+
Internal session pool is configured with options like `ydb.WithSessionPoolSizeLimit()` and other.
72
+
Unlike the session pool in the native driver, `database/sql` contains a different implementation of the session pool, which is configured with `*sql.DB.SetMaxOpenConns` and `*sql.DB.SetMaxIdleConns`.
73
+
Lifetime of a `YDB` session depends on driver configuration and error occurance, such as `sql.driver.ErrBadConn`.
74
+
`YDB` driver for `database/sql` includes the logic to transform the internal `YDB` error codes into `sql.driver.ErrBadConn` and other retryable and non-retryable error types.
78
75
79
-
## Execute queries <aname="queries"></a>
76
+
In most cases the implementation of `database/sql` driver for YDB allows to complete queries without user-visible errors.
77
+
But some errors need to be handled on the client side, by re-running not a single operation, but a complete transaction.
78
+
Therefore the transaction logic needs to be wrapped with retry helpers, such as `retry.Do` or `retry.DoTx` (see more about retry helpers in the [retry section](#retry)).
80
79
81
-
### On database object <aname="queries-db"></a>
80
+
## Query execution <aname="queries"></a>
81
+
82
+
### Queries on database object <aname="queries-db"></a>
82
83
```go
83
84
rows, err:= db.QueryContext(ctx,
84
-
"SELECT series_id, title, release_date FROM /full/path/of/table/series;"
85
+
"SELECT series_id, title, release_date FROM `/full/path/of/table/series`;"
85
86
)
86
87
if err != nil {
87
88
log.Fatal(err)
@@ -104,19 +105,23 @@ if err = rows.Err(); err != nil { // always check final rows err
104
105
}
105
106
```
106
107
107
-
### With transaction <aname="queries-tx"></a>
108
-
Supports only `default` transaction options which mapped to `YDB``SerializableReadWrite` transaction settings.
108
+
### Queries on transaction object <aname="queries-tx"></a>
109
+
Query execution on transaction object supports only `default` transaction options
110
+
which are mapped to `YDB``SerializableReadWrite` transaction settings.
111
+
112
+
`YDB`'s `OnlineReadOnly` and `StaleReadOnly` transaction settings are not compatible
113
+
with interactive transactions such as `database/sql`'s `*sql.Tx`.
114
+
That's why `ydb-go-sdk` implements read-only `sql.LevelSnapshot` with fake transaction
115
+
(temporary, until `YDB` starts to support true snapshot isolation mode).
109
116
110
-
`YDB`'s `OnlineReadOnly` and `StaleReadOnly` transaction settings are not compatible with interactive transactions such as `database/sql`'s `*sql.Tx`.
111
-
That's why `ydb-go-sdk` implements read-only `sql.LevelSnapshot` with fake transaction (temporary, while `YDB` main clusters are supports true snapshot isolation mode)
112
117
```go
113
118
tx, err:= db.BeginTx(ctx, sql.TxOptions{})
114
119
if err != nil {
115
120
log.Fatal(err)
116
121
}
117
122
defer tx.Rollback()
118
123
rows, err:= tx.QueryContext(ctx,
119
-
"SELECT series_id, title, release_date FROM /full/path/of/table/series;"
124
+
"SELECT series_id, title, release_date FROM `/full/path/of/table/series`;"
The `YDB` server API is currently requires to select a specific method by specific request type. For example, [DDL](https://en.wikipedia.org/wiki/Data_definition_language) must be called with `table.session.ExecuteSchemeQuery`, [DML](https://en.wikipedia.org/wiki/Data_manipulation_language) must be called with `table.session.Execute`, [DQL](https://en.wikipedia.org/wiki/Data_query_language) may be called with `table.session.Execute` or `table.session.StreamExecuteScanQuery` etc. `YDB` have a `scripting` service also, which provides different query types with single method, but not supports transactions.
151
+
Currently the `YDB` server APIs require the use of a proper GRPC service method depending on the specific request type.
152
+
In particular, [DDL](https://en.wikipedia.org/wiki/Data_definition_language) must be called through `table.session.ExecuteSchemeQuery`,
153
+
[DML](https://en.wikipedia.org/wiki/Data_manipulation_language) needs `table.session.Execute`, and
154
+
[DQL](https://en.wikipedia.org/wiki/Data_query_language) should be passed via `table.session.Execute` or `table.session.StreamExecuteScanQuery`.
155
+
`YDB` also has a so-called "scripting" service, which supports different query types within a single method,
156
+
but without support for transactions.
146
157
147
-
That's why needs to select query mode on client side currently.
158
+
Unfortunately, this leads to the need to choose the proper query mode on the application side.
148
159
149
-
`YDB` team have a roadmap goal to implements a single method for executing different query types.
160
+
`YDB` team has a roadmap goal to implement a single universal service method for executing
161
+
different query types and without the limitations of the "scripting" service method.
150
162
151
-
`database/sql` driver implementation for `YDB` supports next query modes:
163
+
`database/sql` driver implementation for `YDB` supports the following query modes:
152
164
*`ydb.DataQueryMode` - default query mode, for lookup [DQL](https://en.wikipedia.org/wiki/Data_query_language) queries and [DML](https://en.wikipedia.org/wiki/Data_manipulation_language) queries.
153
-
*`ydb.ExplainQueryMode` - for gettting plan and [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree) of some query
154
-
*`ydb.ScanQueryMode` - for strong[OLAP](https://en.wikipedia.org/wiki/Online_analytical_processing) scenarious, [DQL-only](https://en.wikipedia.org/wiki/Data_query_language) queries. Read more about scan queries in [ydb.tech](https://ydb.tech/en/docs/concepts/scan_query)
165
+
*`ydb.ExplainQueryMode` - for gettting plan and [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree) of the query
166
+
*`ydb.ScanQueryMode` - for heavy[OLAP](https://en.wikipedia.org/wiki/Online_analytical_processing)style scenarious, with[DQL-only](https://en.wikipedia.org/wiki/Data_query_language) queries. Read more about scan queries in [ydb.tech](https://ydb.tech/en/docs/concepts/scan_query)
155
167
*`ydb.SchemeQueryMode` - for [DDL](https://en.wikipedia.org/wiki/Data_definition_language) queries
156
-
*`ydb.ScriptingQueryMode` - for [DDL](https://en.wikipedia.org/wiki/Data_definition_language), [DML](https://en.wikipedia.org/wiki/Data_manipulation_language), [DQL](https://en.wikipedia.org/wiki/Data_query_language) queries (not a [TCL](https://en.wikipedia.org/wiki/SQL#Transaction_controls)). Be careful: queries executes longer than with other query modes and consumes bigger server-side resources
168
+
*`ydb.ScriptingQueryMode` - for [DDL](https://en.wikipedia.org/wiki/Data_definition_language), [DML](https://en.wikipedia.org/wiki/Data_manipulation_language), [DQL](https://en.wikipedia.org/wiki/Data_query_language) queries (not a [TCL](https://en.wikipedia.org/wiki/SQL#Transaction_controls)). Be careful: queries execute longer than with other query modes, and consume more server-side resources
0 commit comments