@@ -23,7 +23,7 @@ import (
2323 "workload/schema"
2424)
2525
26- const createTableSQL = `CREATE TABLE info (
26+ const createTableSQL = `CREATE TABLE info_%d (
2727 col_1 bigint(20) NOT NULL,
2828 col2 bigint(20) NOT NULL,
2929 col3 date NOT NULL,
@@ -139,7 +139,7 @@ const createTableSQL = `CREATE TABLE info (
139139 KEY idx_2 (col2,col3)
140140 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin`
141141
142- const createLogTableSQL = `CREATE TABLE log (
142+ const createLogTableSQL = `CREATE TABLE log_%d (
143143 col110 bigint(20) NOT NULL,
144144 col_1 bigint(20) NOT NULL,
145145 col111 date NOT NULL,
@@ -186,47 +186,75 @@ const createLogTableSQL = `CREATE TABLE log (
186186 col105 varchar(1) NOT NULL DEFAULT 'N',
187187 col106 varchar(256) DEFAULT NULL,
188188 PRIMARY KEY (col5,col111,col110) /*T![clustered_index] NONCLUSTERED */,
189- KEY idx_1 (col5,col3,id ),
189+ KEY idx_1 (col5,col3,col110 ),
190190 KEY idx_2 (col99,col91,col105)
191191) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T! SHARD_ROW_ID_BITS=9 PRE_SPLIT_REGIONS=9 */`
192192
193193type Bank2Workload struct {
194194 infoTableInsertSQL string
195195 logTableInsertSQL string
196+ infoTableUpdateSQL string
197+ logTableUpdateSQL string
196198}
197199
198200func NewBank2Workload () schema.Workload {
199201 var builder strings.Builder
200- builder .WriteString ("insert into info (col5 , col3 , col6 , col2 ,col35 , col12 , col16 , col107 , col101 , col98 , col73 , col27 , col59 , col26 , col72 , col23 , col81 , col34 , col14 , col95 , col60 , col38 , col33 , col_1 , col31 , col104 , col32 , col85 , col4 , col74 , col102 , col7 , col47 , col29 , col69 , col76 , col75 , col94 , col99 , col20 , col68 , col42 , col25 , col57 , col87 , col82 , col50 , col30 , col83 , col19 , col78 , col43 , col62 , col28 , col11 , col49 , col90 , col56 , col109 , col71 , col15 , col51 , col106 , col53 , col22 , col61 , col91 , col46 , col55 , col108 , col105 , col103 , col63 , col36 , col44 , col88 , col18 , col86 , col10 , col70 , col45 , col64 , col24 , col40 , col84 , col67 , col66 , col17 , col9 , col41 , col77 , col54 , col100 , col37 , col21 , col8 , col52 , col48 , col39 , col96 , col80 , col13 , col89 , col79 , col65 , col93 , col97 , col92 , col58 ) values " )
202+ builder .WriteString ("insert into info_%d (col5 , col3 , col6 , col2 ,col35 , col12 , col16 , col107 , col101 , col98 , col73 , col27 , col59 , col26 , col72 , col23 , col81 , col34 , col14 , col95 , col60 , col38 , col33 , col_1 , col31 , col104 , col32 , col85 , col4 , col74 , col102 , col7 , col47 , col29 , col69 , col76 , col75 , col94 , col99 , col20 , col68 , col42 , col25 , col57 , col87 , col82 , col50 , col30 , col83 , col19 , col78 , col43 , col62 , col28 , col11 , col49 , col90 , col56 , col109 , col71 , col15 , col51 , col106 , col53 , col22 , col61 , col91 , col46 , col55 , col108 , col105 , col103 , col63 , col36 , col44 , col88 , col18 , col86 , col10 , col70 , col45 , col64 , col24 , col40 , col84 , col67 , col66 , col17 , col9 , col41 , col77 , col54 , col100 , col37 , col21 , col8 , col52 , col48 , col39 , col96 , col80 , col13 , col89 , col79 , col65 , col93 , col97 , col92 , col58 ) values " )
201203 for r := 0 ; r < 200 ; r ++ {
202204 if r != 0 {
203205 builder .WriteString ("," )
204206 }
205207 builder .WriteString ("(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" )
206208 }
207209 infoTableInsertSQL := builder .String ()
210+ builder .Reset ()
208211
212+ builder .WriteString ("insert into info_%d (col5 , col3 , col6 , col2 ,col35 , col12 , col16 , col107 , col101 , col98 , col73 , col27 , col59 , col26 , col72 , col23 , col81 , col34 , col14 , col95 , col60 , col38 , col33 , col_1 , col31 , col104 , col32 , col85 , col4 , col74 , col102 , col7 , col47 , col29 , col69 , col76 , col75 , col94 , col99 , col20 , col68 , col42 , col25 , col57 , col87 , col82 , col50 , col30 , col83 , col19 , col78 , col43 , col62 , col28 , col11 , col49 , col90 , col56 , col109 , col71 , col15 , col51 , col106 , col53 , col22 , col61 , col91 , col46 , col55 , col108 , col105 , col103 , col63 , col36 , col44 , col88 , col18 , col86 , col10 , col70 , col45 , col64 , col24 , col40 , col84 , col67 , col66 , col17 , col9 , col41 , col77 , col54 , col100 , col37 , col21 , col8 , col52 , col48 , col39 , col96 , col80 , col13 , col89 , col79 , col65 , col93 , col97 , col92 , col58 ) values " )
213+ for r := 0 ; r < 200 ; r ++ {
214+ if r != 0 {
215+ builder .WriteString ("," )
216+ }
217+ builder .WriteString ("(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" )
218+ }
219+ builder .WriteString ("ON DUPLICATE KEY UPDATE col5=VALUES(col5), col3=VALUES(col3), col6=VALUES(col6), col2=VALUES(col2);" )
220+ infoTableUpdateSQL := builder .String ()
209221 builder .Reset ()
210222
211- builder .WriteString ("insert into log (col5 , col111 , id , col84 , col122 , col112 , col121 , col124 , col106 , col125 , col98 , col115 , col116 , col114 , col9 , col94 , col99 , col118 , col95 , col91 , col113 , col87 , col105 , col119 , col_1 , col104 , col8 , col3 , col88 , col96 , col117 , col86 , col85 , col4 , col6 , col126 , col102 , col89 , col7 , col120 , col93 , col90 , col97 , col92 , col123 ) values " )
223+ builder .WriteString ("insert into log_%d (col5 , col111 , col110 , col84 , col122 , col112 , col121 , col124 , col106 , col125 , col98 , col115 , col116 , col114 , col9 , col94 , col99 , col118 , col95 , col91 , col113 , col87 , col105 , col119 , col_1 , col104 , col8 , col3 , col88 , col96 , col117 , col86 , col85 , col4 , col6 , col126 , col102 , col89 , col7 , col120 , col93 , col90 , col97 , col92 , col123 ) values " )
212224 for r := 0 ; r < 200 ; r ++ {
213225 if r != 0 {
214226 builder .WriteString ("," )
215227 }
216228 builder .WriteString ("(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" )
217229 }
218230 logTableInsertSQL := builder .String ()
231+ builder .Reset ()
219232
220- workload := & Bank2Workload {infoTableInsertSQL : infoTableInsertSQL , logTableInsertSQL : logTableInsertSQL }
233+ builder .WriteString ("insert into log_%d (col5 , col111 , col110 , col84 , col122 , col112 , col121 , col124 , col106 , col125 , col98 , col115 , col116 , col114 , col9 , col94 , col99 , col118 , col95 , col91 , col113 , col87 , col105 , col119 , col_1 , col104 , col8 , col3 , col88 , col96 , col117 , col86 , col85 , col4 , col6 , col126 , col102 , col89 , col7 , col120 , col93 , col90 , col97 , col92 , col123 ) values " )
234+ for r := 0 ; r < 200 ; r ++ {
235+ if r != 0 {
236+ builder .WriteString ("," )
237+ }
238+ builder .WriteString ("(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" )
239+ }
240+ builder .WriteString ("ON DUPLICATE KEY UPDATE col5=VALUES(col5), col111=VALUES(col111), col110=VALUES(col110);" )
241+ logTableUpdateSQL := builder .String ()
242+
243+ workload := & Bank2Workload {
244+ infoTableInsertSQL : infoTableInsertSQL ,
245+ logTableInsertSQL : logTableInsertSQL ,
246+ infoTableUpdateSQL : infoTableUpdateSQL ,
247+ logTableUpdateSQL : logTableUpdateSQL ,
248+ }
221249 return workload
222250}
223251
224252func (c * Bank2Workload ) BuildCreateTableStatement (n int ) string {
225- switch n {
253+ switch n % 2 {
226254 case 0 : // info
227- return createTableSQL
255+ return fmt . Sprintf ( createTableSQL , n )
228256 case 1 : // log
229- return createLogTableSQL
257+ return fmt . Sprintf ( createLogTableSQL , n )
230258 default :
231259 panic ("unknown table" )
232260 }
@@ -258,14 +286,15 @@ var largeValuesPool = sync.Pool{
258286}
259287
260288func (c * Bank2Workload ) BuildInsertSqlWithValues (tableN int , batchSize int ) (string , []interface {}) {
261- switch tableN {
289+ values := largeValuesPool .Get ().([]interface {})
290+ defer largeValuesPool .Put (values [:0 ])
291+ rand .Seed (time .Now ().UnixNano ())
292+
293+ switch tableN % 2 {
262294 case 0 : // info
263295 nonPrimaryKeyValues := generateNonPrimaryValuesForTable () // to reduce time, these field we keep same for
264- sql := c .infoTableInsertSQL
265- rand .Seed (time .Now ().UnixNano ())
296+ sql := fmt .Sprintf (c .infoTableInsertSQL , tableN )
266297
267- values := valuesPool .Get ().([]interface {})
268- defer valuesPool .Put (values [:0 ])
269298 // 200 rows one txn
270299 for r := 0 ; r < 200 ; r ++ {
271300 values = append (values , generatePrimaryValuesForTable ()... )
@@ -274,12 +303,9 @@ func (c *Bank2Workload) BuildInsertSqlWithValues(tableN int, batchSize int) (str
274303
275304 return sql , values
276305 case 1 : // log
277- sql := c .logTableInsertSQL
306+ sql := fmt . Sprintf ( c .logTableInsertSQL , tableN )
278307 nonPrimaryKeyValues := generateNonPrimaryValuesForLogTable ()
279- rand .Seed (time .Now ().UnixNano ())
280308
281- values := valuesPool .Get ().([]interface {})
282- defer valuesPool .Put (values [:0 ])
283309 // 200 rows one txn
284310 for r := 0 ; r < 200 ; r ++ {
285311 values = append (values , generatePrimaryValuesForLogTable ()... )
@@ -296,16 +322,23 @@ func (c *Bank2Workload) BuildInsertSqlWithValues(tableN int, batchSize int) (str
296322func (c * Bank2Workload ) BuildUpdateSqlWithValues (opts schema.UpdateOption ) (string , []interface {}) {
297323 rand .Seed (time .Now ().UnixNano ())
298324 var sql string
299- values := make ([]interface {}, 0 , 120 )
300- switch opts .TableIndex {
325+ values := largeValuesPool .Get ().([]interface {})
326+ defer largeValuesPool .Put (values [:0 ])
327+ switch opts .TableIndex % 2 {
301328 case 0 : // info
302- sql = "insert into info (col5 , col3 , col6 , col2 ,col35 , col12 , col16 , col107 , col101 , col98 , col73 , col27 , col59 , col26 , col72 , col23 , col81 , col34 , col14 , col95 , col60 , col38 , col33 , col_1 , col31 , col104 , col32 , col85 , col4 , col74 , col102 , col7 , col47 , col29 , col69 , col76 , col75 , col94 , col99 , col20 , col68 , col42 , col25 , col57 , col87 , col82 , col50 , col30 , col83 , col19 , col78 , col43 , col62 , col28 , col11 , col49 , col90 , col56 , col109 , col71 , col15 , col51 , col106 , col53 , col22 , col61 , col91 , col46 , col55 , col108 , col105 , col103 , col63 , col36 , col44 , col88 , col18 , col86 , col10 , col70 , col45 , col64 , col24 , col40 , col84 , col67 , col66 , col17 , col9 , col41 , col77 , col54 , col100 , col37 , col21 , col8 , col52 , col48 , col39 , col96 , col80 , col13 , col89 , col79 , col65 , col93 , col97 , col92 , col58 ) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE col5=VALUES(col5), col3=VALUES(col3), col6=VALUES(col6), col2=VALUES(col2)"
303- values = append (values , generatePrimaryValuesForTable ()... )
304- values = append (values , generateNonPrimaryValuesForTable ()... )
329+ sql = fmt .Sprintf (c .infoTableUpdateSQL , opts .TableIndex )
330+ nonPrimaryValues := generateNonPrimaryValuesForTable ()
331+ for r := 0 ; r < 200 ; r ++ {
332+ values = append (values , generatePrimaryValuesForTable ()... )
333+ values = append (values , nonPrimaryValues ... )
334+ }
305335 case 1 : // log
306- sql = "insert into log (col5 , col111 , id , col84 , col122 , col112 , col121 , col124 , col106 , col125 , col98 , col115 , col116 , col114 , col9 , col94 , col99 , col118 , col95 , col91 , col113 , col87 , col105 , col119 , col_1 , col104 , col8 , col3 , col88 , col96 , col117 , col86 , col85 , col4 , col6 , col126 , col102 , col89 , col7 , col120 , col93 , col90 , col97 , col92 , col123 ) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE col5=VALUES(col5), col111=VALUES(col111), id=VALUES(id)"
307- values = append (values , generatePrimaryValuesForLogTable ()... )
308- values = append (values , generateNonPrimaryValuesForLogTable ()... )
336+ sql = fmt .Sprintf (c .logTableUpdateSQL , opts .TableIndex )
337+ nonPrimaryValues := generateNonPrimaryValuesForLogTable ()
338+ for r := 0 ; r < 200 ; r ++ {
339+ values = append (values , generatePrimaryValuesForLogTable ()... )
340+ values = append (values , nonPrimaryValues ... )
341+ }
309342 default :
310343 panic ("unknown table" )
311344 }
0 commit comments