H2内存数据库查询非常慢

dha*_*han 2 h2 spring-jdbc

我正在使用H2数据库来提高性能,因此我决定在运行时将数据从MySQL加载到H2数据库.

场景是我创建了三个表作为book,author,book_author.book_author是一个多对多表.

表格书,作者和book_author分别记录了1000,50000和50000.

选择查询

select book.name 
from book, author , book_author 
where book.id = book_author.book_id 
and book_author.author_id = author.id 
and author.name = 'Charles Dickens'
Run Code Online (Sandbox Code Playgroud)

需要7分钟才能执行.

我使用spring-jdbc来创建H2内存数据库.

EmbeddedDatabase database_01 = new EmbeddedDatabaseBuilder().
    setType(EmbeddedDatabaseType.H2).
    addScript("initial_script.sql").
    setName("database_01").build();

JdbcTemplate jdbcTemplate_01 = new JdbcTemplate(database_01);
Run Code Online (Sandbox Code Playgroud)

有人可以建议为什么要花费这么多时间并优化它?

Tho*_*ler 5

你创建了正确的索引吗?另请参阅有关索引文档以及它们在H2中的使用方式.