[#5028] Slow routine overload index calculation in PostgreSQL's code generator

This commit is contained in:
lukaseder 2016-02-02 13:21:38 +01:00
parent 10d9e54160
commit 73992ff07a

View File

@ -51,18 +51,18 @@ import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.max;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.not;
import static org.jooq.impl.DSL.one;
import static org.jooq.impl.DSL.partitionBy;
import static org.jooq.impl.DSL.row;
import static org.jooq.impl.DSL.rowNumber;
import static org.jooq.impl.DSL.select;
import static org.jooq.impl.DSL.selectOne;
import static org.jooq.impl.DSL.trueCondition;
import static org.jooq.impl.DSL.upper;
import static org.jooq.impl.DSL.val;
import static org.jooq.impl.DSL.when;
import static org.jooq.util.postgres.PostgresDSL.arrayAppend;
import static org.jooq.util.postgres.PostgresDSL.oid;
import static org.jooq.util.postgres.information_schema.Tables.ATTRIBUTES;
import static org.jooq.util.postgres.information_schema.Tables.CHECK_CONSTRAINTS;
import static org.jooq.util.postgres.information_schema.Tables.KEY_COLUMN_USAGE;
import static org.jooq.util.postgres.information_schema.Tables.PARAMETERS;
import static org.jooq.util.postgres.information_schema.Tables.ROUTINES;
import static org.jooq.util.postgres.information_schema.Tables.SEQUENCES;
import static org.jooq.util.postgres.information_schema.Tables.TABLES;
@ -650,7 +650,6 @@ public class PostgresDatabase extends AbstractDatabase {
List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();
Routines r1 = ROUTINES.as("r1");
Routines r2 = ROUTINES.as("r2");
for (Record record : create().select(
r1.ROUTINE_SCHEMA,
@ -658,15 +657,9 @@ public class PostgresDatabase extends AbstractDatabase {
r1.SPECIFIC_NAME,
// Ignore the data type when there is at least one out parameter
decode()
.when(DSL.exists(
selectOne()
.from(PARAMETERS)
.where(PARAMETERS.SPECIFIC_SCHEMA.eq(r1.SPECIFIC_SCHEMA))
.and(PARAMETERS.SPECIFIC_NAME.eq(r1.SPECIFIC_NAME))
.and(upper(PARAMETERS.PARAMETER_MODE).ne("IN"))),
val("void"))
when(condition("{0} && ARRAY['o','b']::\"char\"[]", PG_PROC.PROARGMODES), inline("void"))
.otherwise(r1.DATA_TYPE).as("data_type"),
r1.CHARACTER_MAXIMUM_LENGTH,
r1.NUMERIC_PRECISION,
r1.NUMERIC_SCALE,
@ -674,21 +667,11 @@ public class PostgresDatabase extends AbstractDatabase {
r1.TYPE_UDT_NAME,
// Calculate overload index if applicable
decode().when(
DSL.exists(
selectOne()
.from(r2)
.where(r2.ROUTINE_SCHEMA.in(getInputSchemata()))
.and(r2.ROUTINE_SCHEMA.eq(r1.ROUTINE_SCHEMA))
.and(r2.ROUTINE_NAME.eq(r1.ROUTINE_NAME))
.and(r2.SPECIFIC_NAME.ne(r1.SPECIFIC_NAME))),
select(count())
.from(r2)
.where(r2.ROUTINE_SCHEMA.in(getInputSchemata()))
.and(r2.ROUTINE_SCHEMA.eq(r1.ROUTINE_SCHEMA))
.and(r2.ROUTINE_NAME.eq(r1.ROUTINE_NAME))
.and(r2.SPECIFIC_NAME.le(r1.SPECIFIC_NAME)).asField())
.as("overload"),
when(
count().over(partitionBy(r1.ROUTINE_SCHEMA, r1.ROUTINE_NAME)).gt(one()),
rowNumber().over(partitionBy(r1.ROUTINE_SCHEMA, r1.ROUTINE_NAME).orderBy(r1.SPECIFIC_NAME))
).as("overload"),
PG_PROC.PROISAGG)
.from(r1)