vapor / fluent-kit

Swift ORM (queries, models, and relations) for NoSQL and SQL databases
MIT License
217 stars 116 forks source link

make insert query column ordering deterministic #556

Closed rausnitz closed 1 year ago

rausnitz commented 1 year ago

When composing insert queries, the order of the columns is non-deterministic. This hurts query monitoring and analytics.

In a Postgres database we work with, SELECT * FROM pg_stat_statements WHERE query like 'INSERT INTO "my_insert_heavy_table"%'; returns more than 3,100 rows. The relevant table my_insert_heavy_table has many columns, thus many possible column orders when it's non-deterministic. I think if we make the order deterministic, these 3,100 different queries could be treated as one query for monitoring purposes.

Resolves https://github.com/vapor/fluent-kit/issues/543

gwynne commented 1 year ago

I had an idea for a better way to handle this which not only makes INSERT queries behave deterministically, but also actually improves the performance instead of worsening it. I implemented it on an identically-named branch which I will open a new PR for momentarily.