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