Answer the question
In order to leave comments, you need to log in
What is the practical difference between the two types VIRTUAL and STORED?
Hello!
CREATE TABLE `tmp_1` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`energy` smallint(5) unsigned NOT NULL DEFAULT 0,
`energy_max` tinyint(3) unsigned NOT NULL DEFAULT 0,
`energy_up` tinyint(3) unsigned GENERATED ALWAYS AS (`energy` < `energy_max`) STORED,
PRIMARY KEY (`id`),
KEY `energy_up` (`energy_up`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT
CREATE TABLE `tmp_2` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`energy` smallint(5) unsigned NOT NULL DEFAULT 0,
`energy_max` tinyint(3) unsigned NOT NULL DEFAULT 0,
`energy_up` tinyint(3) unsigned GENERATED ALWAYS AS (`energy` < `energy_max`) VIRTUAL,
PRIMARY KEY (`id`),
KEY `energy_up` (`energy_up`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT
SELECT id FROM tmp_2 WHERE energy_up = 1
Answer the question
In order to leave comments, you need to log in
In the case of VIRTUAL:
- the result of the operation will be calculated every time it is read;
- the index on this field will be stored in RAM.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question