Skip to content

Conversation

@mertalev
Copy link
Member

Description

It seems it's possible for the tmp table to exist in some cases, possibly when upgrading from older versions. This PR ensures the table is dropped before continuing.

Also moves one of the indices to be created before ingestion as it is noticeably faster in this case.

CREATE INDEX IDX_geodata_gist_earthcoord
ON geodata_places
USING gist (ll_to_earth_public(latitude, longitude))
WITH (fillfactor = 100)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fillfactor param is lost in this PR, does that matter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's intentionally removed because it only makes sense to have it if there are no inserts to the index after its creation

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also WITH (fillfactor = 100) can be omitted because it's the default in all Postgres versions.

https://www.postgresql.org/docs/current/sql-createtable.html#RELOPTION-FILLFACTOR

100 (complete packing) is the default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table fill factor is 100, but the index fill factor is lower. Setting the index fill factor to 100 only makes sense if the index data is completely static.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Thanks for the correction!
Proper link instead of what I posted before: https://www.postgresql.org/docs/current/sql-createindex.html#INDEX-RELOPTION-FILLFACTOR

B-trees use a default fillfactor of 90

@bo0tzz bo0tzz requested a review from zackpollard May 24, 2025 15:46
@zackpollard
Copy link
Member

I'll take a look at this on Tuesday. I'm sure I made a migration to drop the tmp tables if they existed.

@zackpollard
Copy link
Member

zackpollard commented May 27, 2025

This should be impossible

await queryRunner.query(`DROP TABLE IF EXISTS "geodata_places_tmp"`);

@jrasm91 jrasm91 merged commit a068a41 into main Jul 1, 2025
54 of 55 checks passed
@jrasm91 jrasm91 deleted the fix/server-geodata-tmp-table branch July 1, 2025 03:28
@skatsubo
Copy link
Collaborator

skatsubo commented Jul 26, 2025

This should be impossible

await queryRunner.query(`DROP TABLE IF EXISTS "geodata_places_tmp"`);

#17914
Looks like flip-flopping 1.132.1 -> 1.131.3 -> 1.132.1 + interrupting container on 1.131.3 while in geodata loading => caused this behavior:

  • lingering _tmp table after 1.131.3
  • no cleanup of _tmp afterwards (on the second 1.132.1) because the cleanup migration was already applied on the first 1.132.1

@zackpollard
Copy link
Member

This should be impossible

await queryRunner.query(`DROP TABLE IF EXISTS "geodata_places_tmp"`);

#17914 Looks like flip-flopping 1.132.1 -> 1.131.3 -> 1.132.1 + interrupting container on 1.131.3 while in geodata loading => caused this behavior:

* lingering `_tmp` table after 1.131.3

* no cleanup of `_tmp` afterwards (on the second 1.132.1) because the cleanup migration was already applied on the first 1.132.1

Interesting observation, perhaps we should specifically block downgrades after migrations are applied without also rolling back your database 🤔

ollioddi pushed a commit to ollioddi/immich that referenced this pull request Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants