Jacob
Jacob

Reputation: 2061

Why does INNODB_SYS_TABLES.N_COLS show 3+columns for every table?

I just installed MySQL 5.6 development release build to check some improvement in performance_schema and information_schema. And, I found this-

In sakila.actor table there are 4 columns. Checking from information_schema.INNODB_SYS_TABLES column-N_COLS shows 7 for actor instead of 4. I can see that for each table N_COLS shows 3+columns.

sakila.actor-

CREATE TABLE `actor` (
  `actor_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `first_name` varchar(256) NOT NULL,
  `last_name` varchar(45) NOT NULL,
  `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`actor_id`),
  KEY `last_name` (`last_name`,`actor_id`)
) ENGINE=InnoDB

SELECT * FROM information_schema.INNODB_SYS_TABLES;

TABLE_ID  NAME                        FLAG  N_COLS   SPACE  
--------  ------------------------  ------  ------  --------
      11  SYS_FOREIGN                    0       7         0
      12  SYS_FOREIGN_COLS               0       7         0
      38  sakila/actor                   1       7         0
      39  sakila/actor_info              1       7         0

From the docs it says N_COLS= The number of columns in the table.

So why does it show 3+columns for every table? Any idea?

Upvotes: 2

Views: 336

Answers (1)

jcho360
jcho360

Reputation: 3759

I found this on internet, it's because InnoDB adds three hidden columns (DB_ROW_ID, DB_TRX_ID, DB_ROLL_PTR)

you can look the source here

Upvotes: 2

Related Questions