@@ -65,14 +65,18 @@ func TestLRUPCPut(t *testing.T) {
65
65
{types .NewFieldType (mysql .TypeFloat ), types .NewFieldType (mysql .TypeLong )},
66
66
{types .NewFieldType (mysql .TypeFloat ), types .NewFieldType (mysql .TypeInt24 )},
67
67
}
68
+ limitParams := [][]uint64 {
69
+ {1 }, {2 }, {3 }, {4 }, {5 },
70
+ }
68
71
69
72
// one key corresponding to multi values
70
73
for i := 0 ; i < 5 ; i ++ {
71
74
keys [i ] = & planCacheKey {database : strconv .FormatInt (int64 (1 ), 10 )}
72
75
vals [i ] = & PlanCacheValue {
73
- ParamTypes : pTypes [i ],
76
+ ParamTypes : pTypes [i ],
77
+ limitOffsetAndCount : limitParams [i ],
74
78
}
75
- lru .Put (keys [i ], vals [i ], pTypes [i ])
79
+ lru .Put (keys [i ], vals [i ], pTypes [i ], limitParams [ i ] )
76
80
}
77
81
require .Equal (t , lru .size , lru .capacity )
78
82
require .Equal (t , uint (3 ), lru .size )
@@ -103,7 +107,7 @@ func TestLRUPCPut(t *testing.T) {
103
107
104
108
bucket , exist := lru .buckets [string (hack .String (keys [i ].Hash ()))]
105
109
require .True (t , exist )
106
- element , exist := lru .pickFromBucket (bucket , pTypes [i ])
110
+ element , exist := lru .pickFromBucket (bucket , pTypes [i ], limitParams [ i ] )
107
111
require .NotNil (t , element )
108
112
require .True (t , exist )
109
113
require .Equal (t , root , element )
@@ -131,22 +135,25 @@ func TestLRUPCGet(t *testing.T) {
131
135
{types .NewFieldType (mysql .TypeFloat ), types .NewFieldType (mysql .TypeLong )},
132
136
{types .NewFieldType (mysql .TypeFloat ), types .NewFieldType (mysql .TypeInt24 )},
133
137
}
138
+ limitParams := [][]uint64 {
139
+ {1 }, {2 }, {3 }, {4 }, {5 },
140
+ }
134
141
// 5 bucket
135
142
for i := 0 ; i < 5 ; i ++ {
136
143
keys [i ] = & planCacheKey {database : strconv .FormatInt (int64 (i % 4 ), 10 )}
137
- vals [i ] = & PlanCacheValue {ParamTypes : pTypes [i ]}
138
- lru .Put (keys [i ], vals [i ], pTypes [i ])
144
+ vals [i ] = & PlanCacheValue {ParamTypes : pTypes [i ], limitOffsetAndCount : limitParams [ i ] }
145
+ lru .Put (keys [i ], vals [i ], pTypes [i ], limitParams [ i ] )
139
146
}
140
147
141
148
// test for non-existent elements
142
149
for i := 0 ; i < 2 ; i ++ {
143
- value , exists := lru .Get (keys [i ], pTypes [i ])
150
+ value , exists := lru .Get (keys [i ], pTypes [i ], limitParams [ i ] )
144
151
require .False (t , exists )
145
152
require .Nil (t , value )
146
153
}
147
154
148
155
for i := 2 ; i < 5 ; i ++ {
149
- value , exists := lru .Get (keys [i ], pTypes [i ])
156
+ value , exists := lru .Get (keys [i ], pTypes [i ], limitParams [ i ] )
150
157
require .True (t , exists )
151
158
require .NotNil (t , value )
152
159
require .Equal (t , vals [i ], value )
@@ -175,23 +182,29 @@ func TestLRUPCDelete(t *testing.T) {
175
182
{types .NewFieldType (mysql .TypeFloat ), types .NewFieldType (mysql .TypeEnum )},
176
183
{types .NewFieldType (mysql .TypeFloat ), types .NewFieldType (mysql .TypeDate )},
177
184
}
185
+ limitParams := [][]uint64 {
186
+ {1 }, {2 }, {3 },
187
+ }
178
188
for i := 0 ; i < 3 ; i ++ {
179
189
keys [i ] = & planCacheKey {database : strconv .FormatInt (int64 (i ), 10 )}
180
- vals [i ] = & PlanCacheValue {ParamTypes : pTypes [i ]}
181
- lru .Put (keys [i ], vals [i ], pTypes [i ])
190
+ vals [i ] = & PlanCacheValue {
191
+ ParamTypes : pTypes [i ],
192
+ limitOffsetAndCount : limitParams [i ],
193
+ }
194
+ lru .Put (keys [i ], vals [i ], pTypes [i ], []uint64 {})
182
195
}
183
196
require .Equal (t , 3 , int (lru .size ))
184
197
185
198
lru .Delete (keys [1 ])
186
- value , exists := lru .Get (keys [1 ], pTypes [1 ])
199
+ value , exists := lru .Get (keys [1 ], pTypes [1 ], limitParams [ 1 ] )
187
200
require .False (t , exists )
188
201
require .Nil (t , value )
189
202
require .Equal (t , 2 , int (lru .size ))
190
203
191
- _ , exists = lru .Get (keys [0 ], pTypes [0 ])
204
+ _ , exists = lru .Get (keys [0 ], pTypes [0 ], limitParams [ 0 ] )
192
205
require .True (t , exists )
193
206
194
- _ , exists = lru .Get (keys [2 ], pTypes [2 ])
207
+ _ , exists = lru .Get (keys [2 ], pTypes [2 ], limitParams [ 2 ] )
195
208
require .True (t , exists )
196
209
}
197
210
@@ -207,14 +220,14 @@ func TestLRUPCDeleteAll(t *testing.T) {
207
220
for i := 0 ; i < 3 ; i ++ {
208
221
keys [i ] = & planCacheKey {database : strconv .FormatInt (int64 (i ), 10 )}
209
222
vals [i ] = & PlanCacheValue {ParamTypes : pTypes [i ]}
210
- lru .Put (keys [i ], vals [i ], pTypes [i ])
223
+ lru .Put (keys [i ], vals [i ], pTypes [i ], [] uint64 {} )
211
224
}
212
225
require .Equal (t , 3 , int (lru .size ))
213
226
214
227
lru .DeleteAll ()
215
228
216
229
for i := 0 ; i < 3 ; i ++ {
217
- value , exists := lru .Get (keys [i ], pTypes [i ])
230
+ value , exists := lru .Get (keys [i ], pTypes [i ], [] uint64 {} )
218
231
require .False (t , exists )
219
232
require .Nil (t , value )
220
233
require .Equal (t , 0 , int (lru .size ))
@@ -242,7 +255,7 @@ func TestLRUPCSetCapacity(t *testing.T) {
242
255
for i := 0 ; i < 5 ; i ++ {
243
256
keys [i ] = & planCacheKey {database : strconv .FormatInt (int64 (1 ), 10 )}
244
257
vals [i ] = & PlanCacheValue {ParamTypes : pTypes [i ]}
245
- lru .Put (keys [i ], vals [i ], pTypes [i ])
258
+ lru .Put (keys [i ], vals [i ], pTypes [i ], [] uint64 {} )
246
259
}
247
260
require .Equal (t , lru .size , lru .capacity )
248
261
require .Equal (t , uint (5 ), lru .size )
@@ -292,7 +305,7 @@ func TestIssue37914(t *testing.T) {
292
305
val := & PlanCacheValue {ParamTypes : pTypes }
293
306
294
307
require .NotPanics (t , func () {
295
- lru .Put (key , val , pTypes )
308
+ lru .Put (key , val , pTypes , [] uint64 {} )
296
309
})
297
310
}
298
311
@@ -313,7 +326,7 @@ func TestIssue38244(t *testing.T) {
313
326
for i := 0 ; i < 5 ; i ++ {
314
327
keys [i ] = & planCacheKey {database : strconv .FormatInt (int64 (i ), 10 )}
315
328
vals [i ] = & PlanCacheValue {ParamTypes : pTypes [i ]}
316
- lru .Put (keys [i ], vals [i ], pTypes [i ])
329
+ lru .Put (keys [i ], vals [i ], pTypes [i ], [] uint64 {} )
317
330
}
318
331
require .Equal (t , lru .size , lru .capacity )
319
332
require .Equal (t , uint (3 ), lru .size )
@@ -334,15 +347,15 @@ func TestLRUPlanCacheMemoryUsage(t *testing.T) {
334
347
for i := 0 ; i < 3 ; i ++ {
335
348
k := randomPlanCacheKey ()
336
349
v := randomPlanCacheValue (pTypes )
337
- lru .Put (k , v , pTypes )
350
+ lru .Put (k , v , pTypes , [] uint64 {} )
338
351
res += k .MemoryUsage () + v .MemoryUsage ()
339
352
require .Equal (t , lru .MemoryUsage (), res )
340
353
}
341
354
// evict
342
355
p := & PhysicalTableScan {}
343
356
k := & planCacheKey {database : "3" }
344
357
v := & PlanCacheValue {Plan : p }
345
- lru .Put (k , v , pTypes )
358
+ lru .Put (k , v , pTypes , [] uint64 {} )
346
359
res += k .MemoryUsage () + v .MemoryUsage ()
347
360
for kk , vv := range evict {
348
361
res -= kk .(* planCacheKey ).MemoryUsage () + vv .(* PlanCacheValue ).MemoryUsage ()
0 commit comments