HQL very slow

A HQL query I use is very slow.
SELECT
    CONCAT(t.javaType,
    'µ',
    t.systemName) as v,
    CASE
        WHEN SIZE(t.SQLDatabaseColumns) > 0 THEN CONCAT(t.systemName,
        ' (',
        SIZE(t.SQLDatabaseColumns),
        ')')
        ELSE t.systemName
    END as name
FROM
    SQLDatabaseType t
WHERE
    t.database.id = :db
ORDER BY
    SIZE(t.SQLDatabaseColumns) DESC,
    LENGTH(t.systemName) ASC,
    SUBSTR(t.systemName,
    1,
    1) DESC


What the query should do:
The Query should output two columns:
1. Integerµint8 as a concat of the java-type, the letter 'µ' and then the database-native type.
2. int8 (29) what means that the type int8 is used 29 times.

Ok, the reason why this query is slow is: SIZE(t.SQLDatabaseColumn) is executed multiple times.

How to improve the speed in HQL?
Was this page helpful?