Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion grafast/dataplan-pg/src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ ${duration}
const batchSize = batch.length;
for (let batchIndex = 0; batchIndex < batchSize; batchIndex++) {
const { queryValues, resultIndex } = batch[batchIndex];
const identifiersJSON = JSON.stringify(queryValues); // PERF: Canonical? Manual for perf?
const queryValuesObj = { ...queryValues };
const identifiersJSON = JSON.stringify(queryValuesObj); // PERF: Canonical? Manual for perf?
const existingResult = scopedCache.get(identifiersJSON);
if (existingResult) {
if (debugVerbose.enabled) {
Expand Down
22 changes: 8 additions & 14 deletions grafast/dataplan-pg/src/steps/pgSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3155,7 +3155,7 @@ function buildTheQuery<
const extraSelects: SQL[] = [];

const identifierIndexOffset =
extraSelects.push(sql`${identifiersAlias}.idx`) - 1;
extraSelects.push(sql`(${identifiersAlias}.ord - 1)`) - 1;
// PERF: try and re-use existing trueOrderBySQL selection?
const rowNumberIndexOffset =
forceOrder || limit != null || offset != null
Expand Down Expand Up @@ -3233,19 +3233,13 @@ function buildTheQuery<
*/
const text = `\
select ${wrapperAliasText}.*
from (select ids.ordinality - 1 as idx${
queryValues.length > 0
? `, ${queryValues
.map(({ codec }, idx) => {
return `(ids.value->>${idx})::${
sql.compile(codec.sqlType).text
} as "id${idx}"`;
})
.join(", ")}`
: ""
} from json_array_elements($${
rawSqlValues.length + 1
}::json) with ordinality as ids) as ${identifiersAliasText},
from rows from (json_to_recordset($${rawSqlValues.length + 1}::json) as (${queryValues
.map(({ codec }, idx) => `"${idx}" ${sql.compile(codec.sqlType).text}`)
.join(", ")}))
with ordinality as ${identifiersAliasText} (${[
...queryValues.map((_, idx) => `"id${idx}"`),
"ord",
].join(", ")}),
${lateralText};`;

return { text, rawSqlValues, identifierIndex };
Expand Down
5 changes: 3 additions & 2 deletions postgraphile/postgraphile/__tests__/queries/v4/issue2210.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ from "issue_2210"."some_messages"($1::"uuid") as __some_messages__
limit 51;

select __test_user_result__.*
from (select ids.ordinality - 1 as idx, (ids.value->>0)::"uuid" as "id0" from json_array_elements($1::json) with ordinality as ids) as __test_user_identifiers__,
from rows from (json_to_recordset($1::json) as ("0" "uuid"))
with ordinality as __test_user_identifiers__ ("id0", ord),
lateral (
select
__test_user__."id" as "0",
__test_user__."name" as "1",
__test_user_identifiers__.idx as "2"
(__test_user_identifiers__.ord - 1) as "2"
from "issue_2210"."test_user" as __test_user__
where (
__test_user__."id" = __test_user_identifiers__."id0"
Expand Down
Loading