Adding function parameter limit control for different SQL DBs, every DB has different limits with Postgres being the lowest at 100. We need to fix for wide tables which are related.
This commit is contained in:
parent
949c31d760
commit
9d6fc54a99
|
@ -40,7 +40,6 @@ import { dataFilters, helpers } from "@budibase/shared-core"
|
||||||
import { cloneDeep } from "lodash"
|
import { cloneDeep } from "lodash"
|
||||||
|
|
||||||
type QueryFunction = (query: SqlQuery | SqlQuery[], operation: Operation) => any
|
type QueryFunction = (query: SqlQuery | SqlQuery[], operation: Operation) => any
|
||||||
const MAX_SQS_RELATIONSHIP_FIELDS = 63
|
|
||||||
|
|
||||||
function getBaseLimit() {
|
function getBaseLimit() {
|
||||||
const envLimit = environment.SQL_MAX_ROWS
|
const envLimit = environment.SQL_MAX_ROWS
|
||||||
|
@ -877,6 +876,22 @@ class InternalBuilder {
|
||||||
return `'${unaliased}'${separator}${tableField}`
|
return `'${unaliased}'${separator}${tableField}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maxFunctionParameters() {
|
||||||
|
// functions like say json_build_object() in SQL have a limit as to how many can be performed
|
||||||
|
// before a limit is met, this limit exists in Postgres/SQLite. This can be very important, such as
|
||||||
|
// for JSON column building as part of relationships. We also have a default limit to avoid very complex
|
||||||
|
// functions being built - it is likely this is not necessary or the best way to do it.
|
||||||
|
switch (this.client) {
|
||||||
|
case SqlClient.SQL_LITE:
|
||||||
|
return 127
|
||||||
|
case SqlClient.POSTGRES:
|
||||||
|
return 100
|
||||||
|
// other DBs don't have a limit, but set some sort of limit
|
||||||
|
default:
|
||||||
|
return 200
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addJsonRelationships(
|
addJsonRelationships(
|
||||||
query: Knex.QueryBuilder,
|
query: Knex.QueryBuilder,
|
||||||
fromTable: string,
|
fromTable: string,
|
||||||
|
@ -908,12 +923,10 @@ class InternalBuilder {
|
||||||
let relationshipFields = fields.filter(
|
let relationshipFields = fields.filter(
|
||||||
field => field.split(".")[0] === toAlias
|
field => field.split(".")[0] === toAlias
|
||||||
)
|
)
|
||||||
if (this.client === SqlClient.SQL_LITE) {
|
relationshipFields = relationshipFields.slice(
|
||||||
relationshipFields = relationshipFields.slice(
|
0,
|
||||||
0,
|
Math.floor(this.maxFunctionParameters() / 2)
|
||||||
MAX_SQS_RELATIONSHIP_FIELDS
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
const fieldList: string = relationshipFields
|
const fieldList: string = relationshipFields
|
||||||
.map(field => this.buildJsonField(field))
|
.map(field => this.buildJsonField(field))
|
||||||
.join(",")
|
.join(",")
|
||||||
|
|
Loading…
Reference in New Issue