Skip to content

Commit 79f22d2

Browse files
committed
SQL.md
1 parent ecd61b6 commit 79f22d2

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

SQL.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Behind the scene, `database/sql` APIs are implemented using the native interface
99
1. [Initialization of `database/sql` driver](#init)
1010
* [Configure driver with `ydb.Connector` (recommended way)](#init-connector)
1111
* [Configure driver with data source name or connection string](#init-dsn)
12-
2. [Session pooling](#session-pool)
13-
3. [Client balancing](#balancing)
12+
2. [Client balancing](#balancing)
13+
3. [Session pooling](#session-pool)
1414
4. [Query execution](#queries)
1515
* [Queries on database object](#queries-db)
1616
* [Queries on transaction object](#queries-tx)
@@ -72,21 +72,9 @@ Data source name parameters:
7272
* static credentials with authority part of URI, like `grpcs://root:password@localhost:2135/local`
7373
* `query_mode=scripting` - you can redefine default [DML](https://en.wikipedia.org/wiki/Data_manipulation_language) query mode
7474

75-
## Session pooling <a name="session-pool"></a>
76-
77-
Native driver `ydb-go-sdk/v3` implements the internal session pool, which uses with `db.Table().Do()` or `db.Table().DoTx()` methods.
78-
Internal session pool are configured with options like `ydb.WithSessionPoolSizeLimit()` and other.
79-
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`.
80-
Lifetime of a `YDB` session depends on driver configuration and error occurance, such as `sql.driver.ErrBadConn`.
81-
`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.
82-
83-
In most cases the implementation of `database/sql` driver for YDB allows to complete queries without user-visible errors.
84-
But some errors need to be handled on the client side, by re-running not a single operation, but a complete transaction.
85-
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)).
86-
8775
## Client balancing <a name="balancing"></a>
8876

89-
`database/sql` driver for `YDB` like as native driver for `YDB` use client balancing, which happens on `CreateSession` request.
77+
`database/sql` driver for `YDB` like as native driver for `YDB` use client balancing, which happens on `CreateSession` request.
9078
At this time, native driver choose known node for execute request by according balancer algorithm.
9179
Default balancer algorithm is a `random choice`.
9280
Client balancer may be re-configured with option `ydb.WithBalancer`:
@@ -112,6 +100,18 @@ if err != nil {
112100
db := sql.OpenDB(connector)
113101
```
114102

103+
## Session pooling <a name="session-pool"></a>
104+
105+
Native driver `ydb-go-sdk/v3` implements the internal session pool, which uses with `db.Table().Do()` or `db.Table().DoTx()` methods.
106+
Internal session pool are configured with options like `ydb.WithSessionPoolSizeLimit()` and other.
107+
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`.
108+
Lifetime of a `YDB` session depends on driver configuration and error occurance, such as `sql.driver.ErrBadConn`.
109+
`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.
110+
111+
In most cases the implementation of `database/sql` driver for YDB allows to complete queries without user-visible errors.
112+
But some errors need to be handled on the client side, by re-running not a single operation, but a complete transaction.
113+
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)).
114+
115115
## Query execution <a name="queries"></a>
116116

117117
### Queries on database object <a name="queries-db"></a>

0 commit comments

Comments
 (0)