I have a java applet what has embeeded h2 database, and table with 200.000 rows.
Table:
CREATE TABLE `DB`.`TEST` (
`id` INT UNSIGNED PRIMARY KEY,
`from` VARCHAR(80) NOT NULL,
`from_group` SMALLINT UNSIGNED,
`to` VARCHAR(80) NOT NULL,
`to_group` SMALLINT UNSIGNED,
`type` SMALLINT UNSIGNED NOT NULL,
`class` SMALLINT UNSIGNED NOT NULL,
`direction` TINYINT UNSIGNED NOT NULL,
`start` TIMESTAMP NOT NULL,
`answer` TIMESTAMP ,
`end` TIMESTAMP NOT NULL,
`duration` INT UNSIGNED,
`bill` INT UNSIGNED,
`cost` FLOAT UNSIGNED
)
When i do simple query SELECT * FROM DB.TEST ORDER BY id ASC LIMIT 50 – it’s executes perfectly about 3-4 ms. But when a change order by to desc, situation is change and query takes about 8-10 seconds.
Is anyway solution to make order by faster ?
Thanks
H2 requires that you create a descending index in this case:
That means, the index sorts this column in descending order.