Skip to content

Commit eda2225

Browse files
authored
Merge pull request #268 from ydb-platform/disable-keep-in-cache
* Disabled the `KeepInCache` policy for queries without params
2 parents 27263fb + 3d7dfda commit eda2225

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Disabled the `KeepInCache` policy for queries without params
2+
13
## v3.26.4
24
* Update indirect dependency to `gopkg.in/yaml.v3`
35

internal/table/keep_in_cache_test.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,56 @@ import (
1111

1212
"github.com/ydb-platform/ydb-go-sdk/v3/table"
1313
"github.com/ydb-platform/ydb-go-sdk/v3/table/options"
14+
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
1415
"github.com/ydb-platform/ydb-go-sdk/v3/testutil"
1516
)
1617

1718
func TestQueryCachePolicyKeepInCache(t *testing.T) {
1819
for _, test := range [...]struct {
1920
name string
21+
params *table.QueryParameters
2022
executeDataQueryOptions []options.ExecuteDataQueryOption
2123
keepInCache bool
2224
}{
2325
{
24-
name: "no options",
26+
name: "no params, no options",
27+
params: table.NewQueryParameters(),
28+
executeDataQueryOptions: nil,
29+
keepInCache: false,
30+
},
31+
{
32+
name: "not empty params, no options",
33+
params: table.NewQueryParameters(table.ValueParam("a", types.UTF8Value("b"))),
2534
executeDataQueryOptions: nil,
2635
keepInCache: true,
2736
},
2837
{
29-
name: "with server cache",
38+
name: "no params, with server cache",
39+
params: table.NewQueryParameters(),
3040
executeDataQueryOptions: []options.ExecuteDataQueryOption{
3141
options.WithKeepInCache(true),
3242
},
3343
keepInCache: true,
3444
},
3545
{
36-
name: "no server cache",
46+
name: "not empty params, with server cache",
47+
params: table.NewQueryParameters(table.ValueParam("a", types.UTF8Value("b"))),
48+
executeDataQueryOptions: []options.ExecuteDataQueryOption{
49+
options.WithKeepInCache(true),
50+
},
51+
keepInCache: true,
52+
},
53+
{
54+
name: "no params, no server cache",
55+
params: table.NewQueryParameters(),
56+
executeDataQueryOptions: []options.ExecuteDataQueryOption{
57+
options.WithKeepInCache(false),
58+
},
59+
keepInCache: false,
60+
},
61+
{
62+
name: "not empty params, no server cache",
63+
params: table.NewQueryParameters(table.ValueParam("a", types.UTF8Value("b"))),
3764
executeDataQueryOptions: []options.ExecuteDataQueryOption{
3865
options.WithKeepInCache(false),
3966
},
@@ -81,7 +108,7 @@ func TestQueryCachePolicyKeepInCache(t *testing.T) {
81108
table.CommitTx(),
82109
),
83110
"SELECT 1",
84-
table.NewQueryParameters(),
111+
test.params,
85112
test.executeDataQueryOptions...,
86113
)
87114
if err != nil {

internal/table/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ func (s *session) executeDataQuery(
687687
Parameters: params.Params(),
688688
Query: &query.query,
689689
QueryCachePolicy: &Ydb_Table.QueryCachePolicy{
690-
KeepInCache: true,
690+
KeepInCache: len(params.Params()) > 0,
691691
},
692692
OperationParams: operation.Params(
693693
ctx,

table/table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type Session interface {
107107

108108
// Execute executes query.
109109
//
110-
// By default, Execute have a flag options.WithKeepInCache(true). For redefine behavior -
110+
// By default, Execute have a flag options.WithKeepInCache(true) if params is not empty. For redefine behavior -
111111
// append option options.WithKeepInCache(false)
112112
Execute(
113113
ctx context.Context,

0 commit comments

Comments
 (0)