Hello.

If you don't have an index on GROUP BY column, you need a lot of memory for 
such queries in H2.

You can use the EXPLAIN command to check whether optimization is used or 
not.

create table result(id bigint, name varchar, phone int);

-- Without optimization
explain select id, sum(phone) from result group by id;
> SELECT
>     "ID",
>     SUM("PHONE")
> FROM "PUBLIC"."RESULT"
>     /* PUBLIC.RESULT.tableScan */
> GROUP BY "ID"

create index i on result(id);

-- With optimization
explain select id, sum(phone) from result group by id;
> SELECT
>     "ID",
>     SUM("PHONE")
> FROM "PUBLIC"."RESULT"
>     /* PUBLIC.I */
> GROUP BY "ID"
> /* group sorted */

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/80e83bb0-4789-4744-900e-497961393451%40googlegroups.com.

Reply via email to