Cloud SQL stored procedures

This section describes stored procedures for Cloud SQL instances.

A stored procedure contains SQL code that you can reuse.

To execute a stored procedure, you use the CALL command and replace the following variable:

  • procedure_name is the name of the stored procedure.
 CALL 
  
  procedure_name 
 
 ( 
 parameters 
 ); 
For more information, see the CALL statement reference page.

To create a stored procedure, see CREATE PROCEDURE and CREATE FUNCTION Statements . Cloud SQL doesn't support the CREATE FUNCTION statement. For more information, see Unsupported MySQL features for Cloud SQL .

mysql.addSecondaryIdxOnReplica

mysql.addSecondaryIdxOnReplica

Syntax

 mysql 
 . 
 addSecondaryIdxOnReplica 
 ( 
  IDXTYPE 
 
 , 
  
  IDXNAME 
 
 , 
  
  TABLENAME 
 
 , 
  
  IDXDEFINITION 
 
 , 
  
  IDXOPTION 
 
 ) 

Description

Adds a secondary index on the database. This stored procedure is a wrapper for the CREATE INDEX DDL statement.

  • IDXTYPE – Type of index to create. For example, pass UNIQUE to create a unique index.
  • IDXNAME – Name of the index.
  • TABLENAME – Name of the table in the format of schema.name.
  • IDXDEFINITION – Definition of the index. Do not include outer parentheses.
  • IDXOPTION – Any additional options to pass on index creation. For example, in MySQL 8.0, an option could pass INVISIBLE for an invisible index.

mysql.dropSecondaryIdxOnReplica

Syntax

 mysql 
 . 
 dropSecondaryIdxOnReplica 
 ( 
  IDXNAME 
 
 , 
  
  TABLENAME 
 
 , 
  
  IDXOPTION 
 
 ) 

Description

Drops a secondary index on the database. This stored procedure is a wrapper for the DROP INDEX DDL statement.

  • IDXNAME – Name of the index.
  • TABLENAME – Name of the table in the format of schema.name.
  • IDXOPTION – Any additional options to pass when dropping an index. For example, an algorithm option like INPLACE.

mysql.skipReplicationError

Syntax

 mysql 
 . 
 skipReplicationError 
 () 

Description

Skips a replication error encountered during external server replication and then resumes replication.

You can run this stored procedure only if you've encountered a replication error and the I/O and SQL threads are stopped.

This stored procedure procedure does the following:

  1. Determines if GTID- or binary log position-based replication is being used.

  2. If parallel replication is being used, then the stored procedure first calls START_SLAVE_UNTIL_SQL_AFTER_MTS_GAPS or START_REPLICA UNTIL_SQL_AFTER_MTS_GAPS to ensure that there are no gaps in applied transactions up to the failed transaction. The procedure then temporarily sets the replication configuration to single-threaded.

  3. For binary log position-based replication, the procedure sets SQL_SLAVE_SKIP_COUNTER or SQL_REPLICA_SKIP_COUNTER = 1 to skip the current transaction.

  4. For GTID-based replication, the stored procedure determines the GTID of the current failed transaction based on information in the gtid_executed status variable. The procedure then inserts an empty transaction to backfill that GTID.

  5. If parallel replication was previously disabled, then parallel replication is re-enabled.

  6. The stored procedure resumes replication.

The table mysql.skip_replication_error_history logs all invocations of this stored procedure.

What's next

Design a Mobile Site
View Site in Mobile | Classic
Share by: