Introduction
Looking to optimize your database’s performance and efficiency? Generated Invisible Primary Keys (GIPK) might just be the solution you’re looking for. In this article, we’ll explore how GIPK can simplify the process of adding primary keys to your database, enhancing your data integrity and improving your database’s overall functionality. So, keep reading to learn more and take the first step towards a better database today
Problem Statement
Why GIPK?
Generated Invisible Primary Keys (GIPK)
It eliminates the need to maintain a separate column for the primary key in a table. While using GIPK, an invisible column with a primary key will be automatically created, if that particular table was created without a primary key.
What are Generated Invisible Primary Keys ?
It is an invisible primary key for a table that is created without a primary key column.
This was introduced in MySQL version 8.0.30.
How Generated Invisible Primary Keys Works ?
Advantages:
Limitations:
Working Sample:
Set ‘sql_generate_invisible_primary_key’ server variable as 1.
SET sql_generate_invisible_primary_key= 1;Check if Generated Invisible Primary Keys is enabled.
SELECT @@sql_generate_invisible_primary_key;Note:
‘1’ defines enabled.
‘0’ defines disabled.
Creating a table without primary key constraint.
CREATE TABLE test1 ( name varchar(20), age int ) ;View CREATE TABLE to check GIPK column.
SHOW CREATE TABLE test1 \G ;Automatically generated primary key column is created as ‘my_row_id’.
Inserting record into table.
INSERT INTO test1 ( name, age) VALUES (‘abc’,10),(‘abd’,22) ;SELECT * FROM test1 ;Now the record is inserted with GIPK.
By default the primary key is invisible.
To view the inserted primary key, an alter table command is used.
ALTER TABLE test1 ALTER COLUMN my_row_id SET VISIBLE ;Summary:
GIPK is an invisible primary key that is automatically created for tables without a primary key column. It improves database performance, ensures data integrity, and prevents replication delays. However, it is only available in newer versions of MySQL and is limited to InnoDB tables.
At Mafiree Database Support Services, we provide expert assistance in managing your database, ensuring optimal performance and maximum uptime. If you need help with your database management needs, don’t hesitate to contact us at sales@mafiree.com.
Miru IT Park, Vallankumaranvillai,
Nagercoil, Tamilnadu - 629 002.
Unit 303, Vanguard Rise,
5th Main, Konena Agrahara,
Old Airport Road, Bangalore - 560 017.
Call: +91 6383016411
Email: sales@mafiree.com