hasura / hasura/graphql-engine
Hasura mutations slower than SQL equivalents
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
Database : Chinook, Table : Actors,
Hasura version : 1.3.3,
PG version : 12.5
Test setup : Hasura in local and Postgres is hosted in Heroku, also using `psql` from local
Test query :
```
{
actors(limit:5) {
first_name
last_name
last_update
id
}
}
```
Test equivalent SELECT SQL (via `psql`) :
```
SELECT
coalesce(json_agg("root"), '[]') AS "root"
FROM
(
SELECT
row_to_json(
(
SELECT
"_1_e"
FROM
(
SELECT
"_0_root.base"."first_name" AS "first_name",
"_0_root.base"."last_name" AS "last_name",
"_0_root.base"."last_update" AS "last_update",
"_0_root.base"."id" AS "id"
) AS "_1_e"
)
) AS "root"
FROM
(
SELECT
*
FROM
"public"."actors"
WHERE
('true')
) AS "_0_root.base"
LIMIT
5
) AS "_2_root";
```
Mean Response time with Hasura query ~ 280 ms
Mean Response time with `psql` SELECT SQL ~ 270 ms
**Observation**: Similar time with Hasura or psql
Test mutation :
```
mutation {
insert_actors_one(object: {
first_name: "Sandeep"
last_name: "Raja"
}) {
first_name
last_name
last_update
id
}
}
```
Test equivalent INSERT SQL (via `psql`):
```
WITH "actors__mutation_result_alias" AS (
INSERT INTO
"public"."actors" (
"id",
"first_name",
"last_name",
"last_update"
)
VALUES
(DEFAULT, 'Bamba', 'Dumba', DEFAULT) RETURNING *,
CASE
WHEN 'true' THEN NULL
ELSE "hdb_catalog"."check_violation"('insert check constraint failed')
END
),
"actors__all_columns_alias" AS (
SELECT
"id",
"first_name",
"last_name",
"last_update"
FROM
"actors__mutation_result_alias"
)
SELECT
(
SELECT
coalesce((json_agg("root") -> 0), 'null') AS "root"
FROM
(
SELECT
row_to_json(
(
SELECT
"_1_e"
FROM
(
SELECT
"_0_root.base"."id" AS "id",
"_0_root.base"."first_name" AS "first_name",
"_0_root.base"."last_name" AS "last_name",
"_0_root.base"."last_update" AS "last_update"
) AS "_1_e"
)
) AS "root"
FROM
(
SELECT
*
FROM
"actors__all_columns_alias"
WHERE
('true')
) AS "_0_root.base"
) AS "_2_root"
);
```
Mean Response time with Hasura mutation ~ _**1400 ms**_
Mean Response time with psql INSERT SQL ~ 280 ms
**Observation**: 5x slower
Why is mutation operation so much slower than equivalent mutation SQL whereas there is no tangible difference for queries/reads?
Note: Response time for Hasura queries and mutations obtained from Hasura logs and for SQL statements using PSQL (\timing on).
Contributor guide
Research direction
Start by reproducing the reported Chinook Actors comparison using Hasura 1.3.3, PostgreSQL 12.5, Heroku, and local psql, then compare the logged GraphQL mutation and SQL timings. The issue provides no files, tests, entry points, or defined fix, so completion criteria would need maintainer clarification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, postgres
- Domain
- api, database, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100