go.temporal.io/server@v1.23.0/common/persistence/sql/sqlplugin/mysql/execution_maps.go (about)

     1  // The MIT License
     2  //
     3  // Copyright (c) 2020 Temporal Technologies Inc.  All rights reserved.
     4  //
     5  // Copyright (c) 2020 Uber Technologies, Inc.
     6  //
     7  // Permission is hereby granted, free of charge, to any person obtaining a copy
     8  // of this software and associated documentation files (the "Software"), to deal
     9  // in the Software without restriction, including without limitation the rights
    10  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    11  // copies of the Software, and to permit persons to whom the Software is
    12  // furnished to do so, subject to the following conditions:
    13  //
    14  // The above copyright notice and this permission notice shall be included in
    15  // all copies or substantial portions of the Software.
    16  //
    17  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    18  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    19  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    20  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    21  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    22  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    23  // THE SOFTWARE.
    24  
    25  package mysql
    26  
    27  import (
    28  	"context"
    29  	"database/sql"
    30  	"fmt"
    31  	"strings"
    32  
    33  	"github.com/jmoiron/sqlx"
    34  
    35  	"go.temporal.io/server/common/persistence/sql/sqlplugin"
    36  )
    37  
    38  const (
    39  	deleteMapQryTemplate = `DELETE FROM %v
    40  WHERE
    41  shard_id = ? AND
    42  namespace_id = ? AND
    43  workflow_id = ? AND
    44  run_id = ?`
    45  
    46  	// %[2]v is the columns of the value struct (i.e. no primary key columns), comma separated
    47  	// %[3]v should be %[2]v with colons prepended.
    48  	// i.e. %[3]v = ",".join(":" + s for s in %[2]v)
    49  	// %[4]v should be %[2]v in the format of n=VALUES(n).
    50  	// i.e. %[4]v = ",".join(s + "=VALUES(" + s + ")" for s in %[2]v)
    51  	// So that this query can be used with BindNamed
    52  	// %[5]v should be the name of the key associated with the map
    53  	// e.g. for ActivityInfo it is "schedule_id"
    54  	setKeyInMapQryTemplate = `INSERT INTO %[1]v
    55  (shard_id, namespace_id, workflow_id, run_id, %[5]v, %[2]v)
    56  VALUES
    57  (:shard_id, :namespace_id, :workflow_id, :run_id, :%[5]v, %[3]v) 
    58  ON DUPLICATE KEY UPDATE %[5]v=VALUES(%[5]v), %[4]v;`
    59  
    60  	// %[2]v is the name of the key
    61  	deleteKeyInMapQryTemplate = `DELETE FROM %[1]v
    62  WHERE
    63  shard_id = ? AND
    64  namespace_id = ? AND
    65  workflow_id = ? AND
    66  run_id = ? AND
    67  %[2]v IN ( ? )`
    68  
    69  	// %[1]v is the name of the table
    70  	// %[2]v is the name of the key
    71  	// %[3]v is the value columns, separated by commas
    72  	getMapQryTemplate = `SELECT %[2]v, %[3]v FROM %[1]v
    73  WHERE
    74  shard_id = ? AND
    75  namespace_id = ? AND
    76  workflow_id = ? AND
    77  run_id = ?`
    78  )
    79  
    80  func stringMap(a []string, f func(string) string) []string {
    81  	b := make([]string, len(a))
    82  	for i, v := range a {
    83  		b[i] = f(v)
    84  	}
    85  	return b
    86  }
    87  
    88  func makeDeleteMapQry(tableName string) string {
    89  	return fmt.Sprintf(deleteMapQryTemplate, tableName)
    90  }
    91  
    92  func makeSetKeyInMapQry(tableName string, nonPrimaryKeyColumns []string, mapKeyName string) string {
    93  	return fmt.Sprintf(setKeyInMapQryTemplate,
    94  		tableName,
    95  		strings.Join(nonPrimaryKeyColumns, ","),
    96  		strings.Join(stringMap(nonPrimaryKeyColumns, func(x string) string {
    97  			return ":" + x
    98  		}), ","),
    99  		strings.Join(stringMap(nonPrimaryKeyColumns, func(x string) string {
   100  			return x + "=VALUES(" + x + ")"
   101  		}), ","),
   102  		mapKeyName)
   103  }
   104  
   105  func makeDeleteKeyInMapQry(tableName string, mapKeyName string) string {
   106  	return fmt.Sprintf(deleteKeyInMapQryTemplate,
   107  		tableName,
   108  		mapKeyName)
   109  }
   110  
   111  func makeGetMapQryTemplate(tableName string, nonPrimaryKeyColumns []string, mapKeyName string) string {
   112  	return fmt.Sprintf(getMapQryTemplate,
   113  		tableName,
   114  		mapKeyName,
   115  		strings.Join(nonPrimaryKeyColumns, ","))
   116  }
   117  
   118  var (
   119  	// Omit shard_id, run_id, namespace_id, workflow_id, schedule_id since they're in the primary key
   120  	activityInfoColumns = []string{
   121  		"data",
   122  		"data_encoding",
   123  	}
   124  	activityInfoTableName = "activity_info_maps"
   125  	activityInfoKey       = "schedule_id"
   126  
   127  	deleteActivityInfoMapQry      = makeDeleteMapQry(activityInfoTableName)
   128  	setKeyInActivityInfoMapQry    = makeSetKeyInMapQry(activityInfoTableName, activityInfoColumns, activityInfoKey)
   129  	deleteKeyInActivityInfoMapQry = makeDeleteKeyInMapQry(activityInfoTableName, activityInfoKey)
   130  	getActivityInfoMapQry         = makeGetMapQryTemplate(activityInfoTableName, activityInfoColumns, activityInfoKey)
   131  )
   132  
   133  // ReplaceIntoActivityInfoMaps replaces one or more rows in activity_info_maps table
   134  func (mdb *db) ReplaceIntoActivityInfoMaps(
   135  	ctx context.Context,
   136  	rows []sqlplugin.ActivityInfoMapsRow,
   137  ) (sql.Result, error) {
   138  	return mdb.conn.NamedExecContext(ctx,
   139  		setKeyInActivityInfoMapQry,
   140  		rows,
   141  	)
   142  }
   143  
   144  // SelectAllFromActivityInfoMaps reads all rows from activity_info_maps table
   145  func (mdb *db) SelectAllFromActivityInfoMaps(
   146  	ctx context.Context,
   147  	filter sqlplugin.ActivityInfoMapsAllFilter,
   148  ) ([]sqlplugin.ActivityInfoMapsRow, error) {
   149  	var rows []sqlplugin.ActivityInfoMapsRow
   150  	if err := mdb.conn.SelectContext(ctx,
   151  		&rows,
   152  		getActivityInfoMapQry,
   153  		filter.ShardID,
   154  		filter.NamespaceID,
   155  		filter.WorkflowID,
   156  		filter.RunID,
   157  	); err != nil {
   158  		return nil, err
   159  	}
   160  	for i := 0; i < len(rows); i++ {
   161  		rows[i].ShardID = filter.ShardID
   162  		rows[i].NamespaceID = filter.NamespaceID
   163  		rows[i].WorkflowID = filter.WorkflowID
   164  		rows[i].RunID = filter.RunID
   165  	}
   166  	return rows, nil
   167  }
   168  
   169  // DeleteFromActivityInfoMaps deletes one or more rows from activity_info_maps table
   170  func (mdb *db) DeleteFromActivityInfoMaps(
   171  	ctx context.Context,
   172  	filter sqlplugin.ActivityInfoMapsFilter,
   173  ) (sql.Result, error) {
   174  	query, args, err := sqlx.In(
   175  		deleteKeyInActivityInfoMapQry,
   176  		filter.ShardID,
   177  		filter.NamespaceID,
   178  		filter.WorkflowID,
   179  		filter.RunID,
   180  		filter.ScheduleIDs,
   181  	)
   182  	if err != nil {
   183  		return nil, err
   184  	}
   185  	return mdb.conn.ExecContext(ctx,
   186  		mdb.conn.Rebind(query),
   187  		args...,
   188  	)
   189  }
   190  
   191  // DeleteAllFromActivityInfoMaps deletes all rows from activity_info_maps table
   192  func (mdb *db) DeleteAllFromActivityInfoMaps(
   193  	ctx context.Context,
   194  	filter sqlplugin.ActivityInfoMapsAllFilter,
   195  ) (sql.Result, error) {
   196  	return mdb.conn.ExecContext(ctx,
   197  		deleteActivityInfoMapQry,
   198  		filter.ShardID,
   199  		filter.NamespaceID,
   200  		filter.WorkflowID,
   201  		filter.RunID,
   202  	)
   203  }
   204  
   205  var (
   206  	timerInfoColumns = []string{
   207  		"data",
   208  		"data_encoding",
   209  	}
   210  	timerInfoTableName = "timer_info_maps"
   211  	timerInfoKey       = "timer_id"
   212  
   213  	deleteTimerInfoMapSQLQuery      = makeDeleteMapQry(timerInfoTableName)
   214  	setKeyInTimerInfoMapSQLQuery    = makeSetKeyInMapQry(timerInfoTableName, timerInfoColumns, timerInfoKey)
   215  	deleteKeyInTimerInfoMapSQLQuery = makeDeleteKeyInMapQry(timerInfoTableName, timerInfoKey)
   216  	getTimerInfoMapSQLQuery         = makeGetMapQryTemplate(timerInfoTableName, timerInfoColumns, timerInfoKey)
   217  )
   218  
   219  // ReplaceIntoTimerInfoMaps replaces one or more rows in timer_info_maps table
   220  func (mdb *db) ReplaceIntoTimerInfoMaps(
   221  	ctx context.Context,
   222  	rows []sqlplugin.TimerInfoMapsRow,
   223  ) (sql.Result, error) {
   224  	return mdb.conn.NamedExecContext(ctx,
   225  		setKeyInTimerInfoMapSQLQuery,
   226  		rows,
   227  	)
   228  }
   229  
   230  // SelectAllFromTimerInfoMaps reads all rows from timer_info_maps table
   231  func (mdb *db) SelectAllFromTimerInfoMaps(
   232  	ctx context.Context,
   233  	filter sqlplugin.TimerInfoMapsAllFilter,
   234  ) ([]sqlplugin.TimerInfoMapsRow, error) {
   235  	var rows []sqlplugin.TimerInfoMapsRow
   236  	if err := mdb.conn.SelectContext(ctx,
   237  		&rows,
   238  		getTimerInfoMapSQLQuery,
   239  		filter.ShardID,
   240  		filter.NamespaceID,
   241  		filter.WorkflowID,
   242  		filter.RunID,
   243  	); err != nil {
   244  		return nil, err
   245  	}
   246  	for i := 0; i < len(rows); i++ {
   247  		rows[i].ShardID = filter.ShardID
   248  		rows[i].NamespaceID = filter.NamespaceID
   249  		rows[i].WorkflowID = filter.WorkflowID
   250  		rows[i].RunID = filter.RunID
   251  	}
   252  	return rows, nil
   253  }
   254  
   255  // DeleteFromTimerInfoMaps deletes one or more rows from timer_info_maps table
   256  func (mdb *db) DeleteFromTimerInfoMaps(
   257  	ctx context.Context,
   258  	filter sqlplugin.TimerInfoMapsFilter,
   259  ) (sql.Result, error) {
   260  	query, args, err := sqlx.In(
   261  		deleteKeyInTimerInfoMapSQLQuery,
   262  		filter.ShardID,
   263  		filter.NamespaceID,
   264  		filter.WorkflowID,
   265  		filter.RunID,
   266  		filter.TimerIDs,
   267  	)
   268  	if err != nil {
   269  		return nil, err
   270  	}
   271  	return mdb.conn.ExecContext(ctx,
   272  		mdb.conn.Rebind(query),
   273  		args...,
   274  	)
   275  }
   276  
   277  // DeleteAllFromTimerInfoMaps deletes all rows from timer_info_maps table
   278  func (mdb *db) DeleteAllFromTimerInfoMaps(
   279  	ctx context.Context,
   280  	filter sqlplugin.TimerInfoMapsAllFilter,
   281  ) (sql.Result, error) {
   282  	return mdb.conn.ExecContext(ctx,
   283  		deleteTimerInfoMapSQLQuery,
   284  		filter.ShardID,
   285  		filter.NamespaceID,
   286  		filter.WorkflowID,
   287  		filter.RunID,
   288  	)
   289  }
   290  
   291  var (
   292  	childExecutionInfoColumns = []string{
   293  		"data",
   294  		"data_encoding",
   295  	}
   296  	childExecutionInfoTableName = "child_execution_info_maps"
   297  	childExecutionInfoKey       = "initiated_id"
   298  
   299  	deleteChildExecutionInfoMapQry      = makeDeleteMapQry(childExecutionInfoTableName)
   300  	setKeyInChildExecutionInfoMapQry    = makeSetKeyInMapQry(childExecutionInfoTableName, childExecutionInfoColumns, childExecutionInfoKey)
   301  	deleteKeyInChildExecutionInfoMapQry = makeDeleteKeyInMapQry(childExecutionInfoTableName, childExecutionInfoKey)
   302  	getChildExecutionInfoMapQry         = makeGetMapQryTemplate(childExecutionInfoTableName, childExecutionInfoColumns, childExecutionInfoKey)
   303  )
   304  
   305  // ReplaceIntoChildExecutionInfoMaps replaces one or more rows in child_execution_info_maps table
   306  func (mdb *db) ReplaceIntoChildExecutionInfoMaps(
   307  	ctx context.Context,
   308  	rows []sqlplugin.ChildExecutionInfoMapsRow,
   309  ) (sql.Result, error) {
   310  	return mdb.conn.NamedExecContext(ctx,
   311  		setKeyInChildExecutionInfoMapQry,
   312  		rows,
   313  	)
   314  }
   315  
   316  // SelectAllFromChildExecutionInfoMaps reads all rows from child_execution_info_maps table
   317  func (mdb *db) SelectAllFromChildExecutionInfoMaps(
   318  	ctx context.Context,
   319  	filter sqlplugin.ChildExecutionInfoMapsAllFilter,
   320  ) ([]sqlplugin.ChildExecutionInfoMapsRow, error) {
   321  	var rows []sqlplugin.ChildExecutionInfoMapsRow
   322  	if err := mdb.conn.SelectContext(ctx,
   323  		&rows,
   324  		getChildExecutionInfoMapQry,
   325  		filter.ShardID,
   326  		filter.NamespaceID,
   327  		filter.WorkflowID,
   328  		filter.RunID,
   329  	); err != nil {
   330  		return nil, err
   331  	}
   332  	for i := 0; i < len(rows); i++ {
   333  		rows[i].ShardID = filter.ShardID
   334  		rows[i].NamespaceID = filter.NamespaceID
   335  		rows[i].WorkflowID = filter.WorkflowID
   336  		rows[i].RunID = filter.RunID
   337  	}
   338  	return rows, nil
   339  }
   340  
   341  // DeleteFromChildExecutionInfoMaps deletes one or more rows from child_execution_info_maps table
   342  func (mdb *db) DeleteFromChildExecutionInfoMaps(
   343  	ctx context.Context,
   344  	filter sqlplugin.ChildExecutionInfoMapsFilter,
   345  ) (sql.Result, error) {
   346  	query, args, err := sqlx.In(
   347  		deleteKeyInChildExecutionInfoMapQry,
   348  		filter.ShardID,
   349  		filter.NamespaceID,
   350  		filter.WorkflowID,
   351  		filter.RunID,
   352  		filter.InitiatedIDs,
   353  	)
   354  	if err != nil {
   355  		return nil, err
   356  	}
   357  	return mdb.conn.ExecContext(ctx,
   358  		mdb.conn.Rebind(query),
   359  		args...,
   360  	)
   361  }
   362  
   363  // DeleteAllFromChildExecutionInfoMaps deletes all rows from child_execution_info_maps table
   364  func (mdb *db) DeleteAllFromChildExecutionInfoMaps(
   365  	ctx context.Context,
   366  	filter sqlplugin.ChildExecutionInfoMapsAllFilter,
   367  ) (sql.Result, error) {
   368  	return mdb.conn.ExecContext(ctx,
   369  		deleteChildExecutionInfoMapQry,
   370  		filter.ShardID,
   371  		filter.NamespaceID,
   372  		filter.WorkflowID,
   373  		filter.RunID,
   374  	)
   375  }
   376  
   377  var (
   378  	requestCancelInfoColumns = []string{
   379  		"data",
   380  		"data_encoding",
   381  	}
   382  	requestCancelInfoTableName = "request_cancel_info_maps"
   383  	requestCancelInfoKey       = "initiated_id"
   384  
   385  	deleteRequestCancelInfoMapQry      = makeDeleteMapQry(requestCancelInfoTableName)
   386  	setKeyInRequestCancelInfoMapQry    = makeSetKeyInMapQry(requestCancelInfoTableName, requestCancelInfoColumns, requestCancelInfoKey)
   387  	deleteKeyInRequestCancelInfoMapQry = makeDeleteKeyInMapQry(requestCancelInfoTableName, requestCancelInfoKey)
   388  	getRequestCancelInfoMapQry         = makeGetMapQryTemplate(requestCancelInfoTableName, requestCancelInfoColumns, requestCancelInfoKey)
   389  )
   390  
   391  // ReplaceIntoRequestCancelInfoMaps replaces one or more rows in request_cancel_info_maps table
   392  func (mdb *db) ReplaceIntoRequestCancelInfoMaps(
   393  	ctx context.Context,
   394  	rows []sqlplugin.RequestCancelInfoMapsRow,
   395  ) (sql.Result, error) {
   396  	return mdb.conn.NamedExecContext(ctx,
   397  		setKeyInRequestCancelInfoMapQry,
   398  		rows,
   399  	)
   400  }
   401  
   402  // SelectAllFromRequestCancelInfoMaps reads all rows from request_cancel_info_maps table
   403  func (mdb *db) SelectAllFromRequestCancelInfoMaps(
   404  	ctx context.Context,
   405  	filter sqlplugin.RequestCancelInfoMapsAllFilter,
   406  ) ([]sqlplugin.RequestCancelInfoMapsRow, error) {
   407  	var rows []sqlplugin.RequestCancelInfoMapsRow
   408  	if err := mdb.conn.SelectContext(ctx,
   409  		&rows, getRequestCancelInfoMapQry,
   410  		filter.ShardID,
   411  		filter.NamespaceID,
   412  		filter.WorkflowID,
   413  		filter.RunID,
   414  	); err != nil {
   415  		return nil, err
   416  	}
   417  	for i := 0; i < len(rows); i++ {
   418  		rows[i].ShardID = filter.ShardID
   419  		rows[i].NamespaceID = filter.NamespaceID
   420  		rows[i].WorkflowID = filter.WorkflowID
   421  		rows[i].RunID = filter.RunID
   422  	}
   423  	return rows, nil
   424  }
   425  
   426  // DeleteFromRequestCancelInfoMaps deletes one or more rows from request_cancel_info_maps table
   427  func (mdb *db) DeleteFromRequestCancelInfoMaps(
   428  	ctx context.Context,
   429  	filter sqlplugin.RequestCancelInfoMapsFilter,
   430  ) (sql.Result, error) {
   431  	query, args, err := sqlx.In(
   432  		deleteKeyInRequestCancelInfoMapQry,
   433  		filter.ShardID,
   434  		filter.NamespaceID,
   435  		filter.WorkflowID,
   436  		filter.RunID,
   437  		filter.InitiatedIDs,
   438  	)
   439  	if err != nil {
   440  		return nil, err
   441  	}
   442  	return mdb.conn.ExecContext(ctx,
   443  		mdb.conn.Rebind(query),
   444  		args...,
   445  	)
   446  }
   447  
   448  // DeleteAllFromRequestCancelInfoMaps deletes all rows from request_cancel_info_maps table
   449  func (mdb *db) DeleteAllFromRequestCancelInfoMaps(
   450  	ctx context.Context,
   451  	filter sqlplugin.RequestCancelInfoMapsAllFilter,
   452  ) (sql.Result, error) {
   453  	return mdb.conn.ExecContext(ctx,
   454  		deleteRequestCancelInfoMapQry,
   455  		filter.ShardID,
   456  		filter.NamespaceID,
   457  		filter.WorkflowID,
   458  		filter.RunID,
   459  	)
   460  }
   461  
   462  var (
   463  	signalInfoColumns = []string{
   464  		"data",
   465  		"data_encoding",
   466  	}
   467  	signalInfoTableName = "signal_info_maps"
   468  	signalInfoKey       = "initiated_id"
   469  
   470  	deleteSignalInfoMapQry      = makeDeleteMapQry(signalInfoTableName)
   471  	setKeyInSignalInfoMapQry    = makeSetKeyInMapQry(signalInfoTableName, signalInfoColumns, signalInfoKey)
   472  	deleteKeyInSignalInfoMapQry = makeDeleteKeyInMapQry(signalInfoTableName, signalInfoKey)
   473  	getSignalInfoMapQry         = makeGetMapQryTemplate(signalInfoTableName, signalInfoColumns, signalInfoKey)
   474  )
   475  
   476  // ReplaceIntoSignalInfoMaps replaces one or more rows in signal_info_maps table
   477  func (mdb *db) ReplaceIntoSignalInfoMaps(
   478  	ctx context.Context,
   479  	rows []sqlplugin.SignalInfoMapsRow,
   480  ) (sql.Result, error) {
   481  	return mdb.conn.NamedExecContext(ctx,
   482  		setKeyInSignalInfoMapQry,
   483  		rows,
   484  	)
   485  }
   486  
   487  // SelectAllFromSignalInfoMaps reads all rows from signal_info_maps table
   488  func (mdb *db) SelectAllFromSignalInfoMaps(
   489  	ctx context.Context,
   490  	filter sqlplugin.SignalInfoMapsAllFilter,
   491  ) ([]sqlplugin.SignalInfoMapsRow, error) {
   492  	var rows []sqlplugin.SignalInfoMapsRow
   493  	if err := mdb.conn.SelectContext(ctx,
   494  		&rows,
   495  		getSignalInfoMapQry,
   496  		filter.ShardID,
   497  		filter.NamespaceID,
   498  		filter.WorkflowID,
   499  		filter.RunID,
   500  	); err != nil {
   501  		return nil, err
   502  	}
   503  	for i := 0; i < len(rows); i++ {
   504  		rows[i].ShardID = filter.ShardID
   505  		rows[i].NamespaceID = filter.NamespaceID
   506  		rows[i].WorkflowID = filter.WorkflowID
   507  		rows[i].RunID = filter.RunID
   508  	}
   509  	return rows, nil
   510  }
   511  
   512  // DeleteFromSignalInfoMaps deletes one or more rows from signal_info_maps table
   513  func (mdb *db) DeleteFromSignalInfoMaps(
   514  	ctx context.Context,
   515  	filter sqlplugin.SignalInfoMapsFilter,
   516  ) (sql.Result, error) {
   517  	query, args, err := sqlx.In(
   518  		deleteKeyInSignalInfoMapQry,
   519  		filter.ShardID,
   520  		filter.NamespaceID,
   521  		filter.WorkflowID,
   522  		filter.RunID,
   523  		filter.InitiatedIDs,
   524  	)
   525  	if err != nil {
   526  		return nil, err
   527  	}
   528  	return mdb.conn.ExecContext(ctx,
   529  		mdb.conn.Rebind(query),
   530  		args...,
   531  	)
   532  }
   533  
   534  // DeleteAllFromSignalInfoMaps deletes all rows from signal_info_maps table
   535  func (mdb *db) DeleteAllFromSignalInfoMaps(
   536  	ctx context.Context,
   537  	filter sqlplugin.SignalInfoMapsAllFilter,
   538  ) (sql.Result, error) {
   539  	return mdb.conn.ExecContext(ctx,
   540  		deleteSignalInfoMapQry,
   541  		filter.ShardID,
   542  		filter.NamespaceID,
   543  		filter.WorkflowID,
   544  		filter.RunID,
   545  	)
   546  }
   547  
   548  const (
   549  	deleteAllSignalsRequestedSetQry = `DELETE FROM signals_requested_sets
   550  WHERE
   551  shard_id = ? AND
   552  namespace_id = ? AND
   553  workflow_id = ? AND
   554  run_id = ?
   555  `
   556  
   557  	createSignalsRequestedSetQry = `INSERT INTO signals_requested_sets
   558  (shard_id, namespace_id, workflow_id, run_id, signal_id) VALUES
   559  (:shard_id, :namespace_id, :workflow_id, :run_id, :signal_id)
   560  ON DUPLICATE KEY UPDATE signal_id = VALUES (signal_id)`
   561  
   562  	deleteSignalsRequestedSetQry = `DELETE FROM signals_requested_sets
   563  WHERE 
   564  shard_id = ? AND
   565  namespace_id = ? AND
   566  workflow_id = ? AND
   567  run_id = ? AND
   568  signal_id IN ( ? )`
   569  
   570  	getSignalsRequestedSetQry = `SELECT signal_id FROM signals_requested_sets WHERE
   571  shard_id = ? AND
   572  namespace_id = ? AND
   573  workflow_id = ? AND
   574  run_id = ?`
   575  )
   576  
   577  // InsertIntoSignalsRequestedSets inserts one or more rows into signals_requested_sets table
   578  func (mdb *db) ReplaceIntoSignalsRequestedSets(
   579  	ctx context.Context,
   580  	rows []sqlplugin.SignalsRequestedSetsRow,
   581  ) (sql.Result, error) {
   582  	return mdb.conn.NamedExecContext(ctx,
   583  		createSignalsRequestedSetQry,
   584  		rows,
   585  	)
   586  
   587  }
   588  
   589  // SelectAllFromSignalsRequestedSets reads all rows from signals_requested_sets table
   590  func (mdb *db) SelectAllFromSignalsRequestedSets(
   591  	ctx context.Context,
   592  	filter sqlplugin.SignalsRequestedSetsAllFilter,
   593  ) ([]sqlplugin.SignalsRequestedSetsRow, error) {
   594  	var rows []sqlplugin.SignalsRequestedSetsRow
   595  	if err := mdb.conn.SelectContext(ctx,
   596  		&rows,
   597  		getSignalsRequestedSetQry,
   598  		filter.ShardID,
   599  		filter.NamespaceID,
   600  		filter.WorkflowID,
   601  		filter.RunID,
   602  	); err != nil {
   603  		return nil, err
   604  	}
   605  	for i := 0; i < len(rows); i++ {
   606  		rows[i].ShardID = filter.ShardID
   607  		rows[i].NamespaceID = filter.NamespaceID
   608  		rows[i].WorkflowID = filter.WorkflowID
   609  		rows[i].RunID = filter.RunID
   610  	}
   611  	return rows, nil
   612  }
   613  
   614  // DeleteFromSignalsRequestedSets deletes one or more rows from signals_requested_sets table
   615  func (mdb *db) DeleteFromSignalsRequestedSets(
   616  	ctx context.Context,
   617  	filter sqlplugin.SignalsRequestedSetsFilter,
   618  ) (sql.Result, error) {
   619  	query, args, err := sqlx.In(
   620  		deleteSignalsRequestedSetQry,
   621  		filter.ShardID,
   622  		filter.NamespaceID,
   623  		filter.WorkflowID,
   624  		filter.RunID,
   625  		filter.SignalIDs,
   626  	)
   627  	if err != nil {
   628  		return nil, err
   629  	}
   630  	return mdb.conn.ExecContext(ctx,
   631  		mdb.conn.Rebind(query),
   632  		args...,
   633  	)
   634  }
   635  
   636  // DeleteAllFromSignalsRequestedSets deletes all rows from signals_requested_sets table
   637  func (mdb *db) DeleteAllFromSignalsRequestedSets(
   638  	ctx context.Context,
   639  	filter sqlplugin.SignalsRequestedSetsAllFilter,
   640  ) (sql.Result, error) {
   641  	return mdb.conn.ExecContext(ctx,
   642  		deleteAllSignalsRequestedSetQry,
   643  		filter.ShardID,
   644  		filter.NamespaceID,
   645  		filter.WorkflowID,
   646  		filter.RunID,
   647  	)
   648  }