[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[],[],null,["# Cloud SQL stored procedures\n\n\u003cbr /\u003e\n\nMySQL \\| [PostgreSQL](/sql/docs/postgres/stored-procedures \"View this page for the PostgreSQL database engine\") \\| [SQL Server](/sql/docs/sqlserver/stored-procedures \"View this page for the SQL Server database engine\")\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis section describes stored procedures for Cloud SQL instances.\n\nA stored procedure contains SQL code that you can reuse.\n| You cannot drop or alter system stored procedures.\n\nTo execute a stored procedure, you use the `CALL` command and replace the\nfollowing variable:\n\n- \u003cvar translate=\"no\"\u003eprocedure_name\u003c/var\u003e is the name of the stored procedure.\n\n```sql\nCALL procedure_name(parameters);\n```\nFor more information, see the [CALL statement](https://dev.mysql.com/doc/refman/8.0/en/call.html) reference page.\n\n\u003cbr /\u003e\n\nTo create a stored procedure, see [CREATE PROCEDURE and CREATE FUNCTION Statements](https://dev.mysql.com/doc/refman/8.0/en/create-procedure.html).\nCloud SQL doesn't support the `CREATE FUNCTION` statement. For more information,\nsee [Unsupported MySQL features for Cloud SQL](/sql/docs/features#unsupported-statements).\n\n\n| **Note:** You cannot run some stored procedures because they require a `sysadmin` role, which isn't available in Cloud SQL.\n\n\u003cbr /\u003e\n\nmysql.addSecondaryIdxOnReplica\n------------------------------\n\n### mysql.addSecondaryIdxOnReplica\n\n**Syntax** \n\n```sql\nmysql.addSecondaryIdxOnReplica(IDXTYPE, IDXNAME, TABLENAME, IDXDEFINITION, IDXOPTION)\n```\n\n**Description**\n\nAdds a secondary index on the database. This stored procedure is a wrapper for\nthe [CREATE INDEX](https://dev.mysql.com/doc/refman/8.0/en/create-index.html) DDL statement.\n\n- \u003cvar translate=\"no\"\u003eIDXTYPE\u003c/var\u003e -- Type of index to create. For example, pass UNIQUE to create a unique index.\n- \u003cvar translate=\"no\"\u003eIDXNAME\u003c/var\u003e -- Name of the index.\n- \u003cvar translate=\"no\"\u003eTABLENAME\u003c/var\u003e -- Name of the table in the format of schema.name.\n- \u003cvar translate=\"no\"\u003eIDXDEFINITION\u003c/var\u003e -- Definition of the index. Do not include outer parentheses.\n- \u003cvar translate=\"no\"\u003eIDXOPTION\u003c/var\u003e -- Any additional options to pass on index creation. For example, in MySQL 8.0, an option could pass INVISIBLE for an invisible index.\n\n### mysql.dropSecondaryIdxOnReplica\n\n**Syntax** \n\n```sql\nmysql.dropSecondaryIdxOnReplica(IDXNAME, TABLENAME, IDXOPTION)\n```\n\n**Description**\n\nDrops a secondary index on the database. This stored procedure is a wrapper for\nthe [DROP INDEX](https://dev.mysql.com/doc/refman/8.0/en/drop-index.html) DDL statement.\n\n- \u003cvar translate=\"no\"\u003eIDXNAME\u003c/var\u003e -- Name of the index.\n- \u003cvar translate=\"no\"\u003eTABLENAME\u003c/var\u003e -- Name of the table in the format of schema.name.\n- \u003cvar translate=\"no\"\u003eIDXOPTION\u003c/var\u003e -- Any additional options to pass when dropping an index. For example, an algorithm option like INPLACE.\n\nWhat's next\n-----------\n\n- Learn how to [add and drop indexes on Cloud SQL read replicas](/sql/docs/mysql/replication/read-replica-indexes)."]]