mirror of
https://github.com/immich-app/immich.git
synced 2026-07-25 14:00:45 +03:00
800,000+ Assets, Performance is unusable #2174
Closed
opened 2026-02-05 05:28:03 +03:00 by OVERLORD
·
26 comments
No Branch/Tag Specified
main
chore/translations
fix/partner-ownership-contention
renovate/machine-learning
renovate/pypi-pillow-vulnerability
renovate/pypi-pydantic-settings-vulnerability
renovate/java-25.x
renovate/mobile
chore/harden-mobile-openapi-gen
renovate/java-21.x
fix/min-faces
refactor/asset-update
feat/merge-people-mobile
chore/face-cluster-abstraction
refactor/search-v3/pr-2a
fcast
fix/android-local-album-date
fix/24545-sync-retry-cx
fix/android-locked-folder-delete
make-sure-memory-widget-render
chore/freezed-example
fix/clamp-local-date-time-to-valid-value
fix/datetime-max-limit
fix/viewer-long-image-aspect
feat/native-core
feat/yucca-integration
refactor/mobile-actions
fix/ws-reconnect-battery
renovate/sharp
renovate/pigeon-27.x
refactor/auto-trash-sync
feat/release-source-branch
refactor/session-repository
fix/library-map-live-bounds-updates
renovate/permission_handler-12.x
renovate/node-24.x
fix/mobile-scroll-velocity-placeholders
fix/library-map-loading-flash
agg23/appbar-experiments
renovate/pep621-lock-file-maintenance-machine-learning
refactor/undo-actions
refactor/actions
feat/restore-action
feat/delete-action
fix/29853-thumbnail-decode-size
bugfix/live-photo-stuck
feature/load-previews
chore/pub-upgrade
custom-app-logo
fix/failed-sync-blocks-resume
feat/ml-hwaccel-testing
feat/workflow-logs
feat/server-chunked-uploads
feat/upload-action
fix-29727
feat/download-tag-action
feat/share-action
feat/album-actions
fix/android-cr3-save
feat/browser-profile-action
feat/cast-slideshow-action
feat/locked-folder-action
fix/unauthorized-memory-creation
feat/context-actions
refactor/action-class
feat/memories-view
refactor/asset-action-filter
feat/archive-action
feat/stack-action
feat/mobile-hls-player
refactor/stack-actions
feat/workflow-asset-tags
fix/timeline-drag-select-stops
fix/featured-photo-thumbnail-cache
fix/album-timeline-date-ordering
chore/album-remove-assets
feat/partner-table-permissions
fix/ocr-after-edit
fix/re-enable-pruning
refactor/delete-restore-actions
apk-build-deployment
edit-photo-stacking
fix/mise-lockfile
feat/web-hls-hover
refactor/store-cleanup
fix/hash-mismatch
refactor/app-metadata
refactor/advanced-settings
refactor/current-user
fix/dedupe-integrity-missing-paths
chore/albums-select
fix/fdroid-meta
refactor/per-asset-backup-flag
fix/av1-threads
fix/pass-secrets
fix/download-progress-stuck
fix/negative-backup-remainder
feat/map-asset-number
test-bump-prerelease
fix/handle-unlinking-motion-photos
fix/date-range-formatting
fix/mobile-album-action-msg
asset-add-to-album-trigger
refactor/face-editor-decoupling
feat/zoom-aware-face-editing
refactor/adaptive-image-dimensions
fix-face-editor-video-preview
fix-stack-face-tag-selection
fix/face-boxes-edit-panel
workflow-webhook-step
feat/hero_view_transitions
fix/map-sidepanel-queries
feat/dart-openapi-generator
claude/share-quality-5d7Gn
drag-drop-ghost-target
refactor/workflow-page
refactor/mobile-upload
fix-scroll-flicker-2
update-mise-lock-file
feat/kysely-0.29
release-candidate-flow-1
fix/mobile-22522-sqlite-2067
fix/job-lock
release-candidate-flow-3
release-candidate-flow-2
show-in-timeline-toggle
fix/mise-windows
plan-local-image-display
fix/remote-thumbnail-fallback
chore/riverpod-update
album-order-per-user
fix/web-timeline-dom-node-retention
chore/svelte-enable-state-referenced-locally
feat/favorite-albums
feat/patch-release-from-branch
fix/oauth-linking
feat/timeline_scroll_buffer
panorama-face-overlay
push-txxyuusptoru
push-zpwsovysllvn
chore/queue-endpoint-migration
fix/remove-from-album
chore/thumbnail-histogram
fix/video-thumbnail-bindthis-regression
fix/scrubber-drag-edge-cases
fix/timeline_layout_row_height
refactor-cancellable-task
uhthomas/fix-mobile-use-timer
uhthomas/fix-mobile-video-controls-key
uhthomas/chore-mobile-search-declarative
owner-role-album-user
feat/livephoto-editing
favorite-albums
uhthomas/fix-mobile-isolate-auth
fix/library-watcher-excludes
chore/library-e2e-to-medium
push-ynllunsvrpxy
fix/dont-delete-offline-library-files
push-zvwwxmvkrspv
push-kywsnvvkwzts
push-xxnxokokzrou
push-voozlrlkxsnu
view-in-timeline-transition
push-uymvmlknxpmx
push-qslzsplnusoz
fix/mobile-video-stall
uhthomas/draft-mobile-image-cache-cancel
push-yquostpqnkxp
feat/vitest-4
claude/offload-icloud-hashing-bI3GZ
midzelis/wip
uhthomas/fix-server-fsync-all
feat/mobile-widget-shared-client
push-lnyuzsutzkqq
push-vqqqxxvkunru
push-wvnmqoswptww
push-nwxlpmyzkyrl
fix/map-webgl-error
fix/mobile-player-fit
feat/panorama-tiles
csp-policy
push-rsywxvptwxuv
refactor/restores-file-interceptor
postgres-socketio
claude/auto-screenshot-web-changes-Y7efI
visual-review/pr-26535
push-lvyturrtwkrq
feat/library-offline-count
fix/mobile-video-aspect-ratio
uhthomas/fix-mobile-search-results
uhthomas/feat-sort-smart-search
uhthomas/chore-mobile-maplibre
uhthomas/mobile-fix-asset-details-album-pop
feat/crawl-wrapper
push-skvzqoozqkpl
feat/edit-filters
feat/pg-queue
refactor/asset-upload
better-project-structure
uhthomas/mobile-feat-asset-viewer-details
fix/ml-rocm-build
feat/asset-file-apis
feature/bottom-buttons-order
sqlite_thumbs
fix-keep-correct-ios-shared-album-asset
push-vpxwmwwxwnvw
fix-migration-width-height
shared-deep-link-handler
feat/thumbnail-native-clients
feat/platform-clients
fix/foreground-cloud-sync
filter-by-person
refactor/sidebar
fix/merged-edited-assets
feat/create-job-with-dto
feat/ios-fastlane-match
match-signing
fix-update-time-update-timeline
feat/modal-routes
feature/mobile-view-asset-owner
feat/system-settings
feature/show-activity-count
feat/location-favorites
feature/rearrange-buttons-2
fix/download-storage-template
chore/originals-in-asset-files
ben/tree-a11y
new-search-filter-ui
refactor/expectSelectedReadonly
refactor/mobile-grdb
feat/mobile-native-local-sync
refactor/timeline_ops
fix/scrubber_end
refactor/virtualsegment
refactor/rename_daymonth_groups
fix-remote-sync-clean-up
debug/cf-chunked-uploads
feat/search-filter-album/web
feat/session-permissions
feat/mobile-dynamic-thumbnails
refactor/extract_photostream
refactor/rename_load_api
refactor/timeline2
refactor/timeline3
feat-no-thumbhash-cache
feat/mobile-hdr-images
feat/beta-background-upload
fix/beta-timeline-memories-setting
fix/failed-uploads-not-removed
feat/groups
drift-map-page
feat/add-to-album-action
track-livephotos
feat/maintenance-worker
refactor/server-side-dedupe
feat/integrity-checks
dev/recognition-eval
lighter_buckets_test
perf/postgres-queue
tmp/demo-snapshot-preview
fix/server-migration-file-extension
rknn-toolkit-lite2
feature/Add-rocm-support-for-machine-learning
chore/async-hash-file
feat/shared-link-view-count
feat/graphql
no-video-player
fix/server-qsv-output-format
chore/server-geodata-tweaks
mobile/native-video-player-no-hero
feat/local-tileserver
feat/ml-armnn-conversion
chore/handle-output_dims
feat/capacitor-mobile-app-poc
feat/server-nvenc-hw-decoding
web/automation-ui
object-storage
ml/tflite
feat/ml-export-cli
v3.0.3
v3.0.2
v3.0.1
v3.0.0
v3.0.0-rc.4
v3.0.0-rc.3
v3.0.0-rc.2
v3.0.0-rc.1
v3.0.0-rc.0
v2.7.5
v2.7.4
v2.7.3
v2.7.2
v2.7.1
v2.7.0
v2.6.3
v2.6.2
v2.6.1
v2.6.0
v2.5.6
v2.5.5
v2.5.4
v2.5.3
v2.5.2
v2.5.1
v2.5.0
v2.4.1
v2.4.0
v2.3.1
v2.3.0
v2.2.3
v2.2.2
v2.2.1
v2.2.0
v2.1.0
v2.0.1
v2.0.0
v1.144.1
v1.144.0
v1.143.1
v1.143.0
v1.142.1
v1.142.0
v1.141.1
v1.141.0
v1.140.1
v1.140.0
v1.139.4
v1.139.3
v1.139.2
v1.139.1
v1.139.0
v1.138.1
v1.138.0
v1.137.3
v1.137.2
v1.137.1
v1.137.0
v1.136.0
v1.135.3
v1.135.2
v1.135.1
v1.135.0
v1.134.0
v1.133.1
v1.133.0
v1.132.3
v1.132.2
v1.132.1
v1.132.0
v1.131.3
v1.131.2
v1.131.1
v1.131.0
v1.130.3
v1.130.2
v1.130.1
v1.130.0
v1.129.0
v1.128.0
v1.127.0
v1.126.1
v1.126.0
v1.125.7
v1.125.6
v1.125.5
v1.125.4
v1.125.3
v1.125.2
v1.125.1
v1.125.0
v1.124.2
v1.124.1
v1.124.0
v1.123.0
v1.122.3
v1.122.2
v1.122.1
v1.122.0
v1.121.0
v1.120.2
v1.120.1
v1.120.0
v1.119.1
v1.119.0
v1.118.2
v1.118.1
v1.118.0
v1.117.0
v1.116.2
v1.116.1
v1.116.0
v1.115.0
v1.114.0
v1.113.1
v1.113.0
v1.112.1
v1.112.0
v1.111.0
v1.110.0
v1.109.2
v1.109.1
v1.109.0
v1.108.0
v1.107.2
v1.107.1
v1.107.0
v1.106.4
v1.106.3
v1.106.2
v1.106.1
v1.106.0
v1.105.1
v1.105.0
v1.104.0
v1.103.1
v1.103.0
v1.102.3
v1.102.2
v1.102.1
v1.102.0
v1.101.0
v1.100.0
v1.99.0
v1.98.2
v1.98.1
v1.98.0
v1.97.0
v1.96.0
v1.95.1
v1.95.0
v1.94.1
v1.94.0
v1.93.3
v1.93.2
v1.93.1
v1.93.0
v1.92.1
v1.92.0
v1.91.4
v1.91.3
v1.91.2
v1.91.1
v1.91.0
v1.90.2
v1.90.1
v1.90.0
v1.89.0
v1.88.2
v1.88.1
v1.88.0
v1.87.0
v1.86.0
v1.85.0
v1.84.0
v1.83.0
v1.82.1
v1.82.0
v1.81.1
v1.81.0
v1.80.0
v1.79.1
v1.79.0
v1.78.1
v1.78.0
v1.77.0
v1.76.1
v1.76.0
v1.75.2
v1.75.1
v1.75.0
v1.74.0
v1.73.0
v1.72.2
v1.72.1
v1.72.0
v1.71.0
v1.70.0
v1.69.0
v1.68.0
v1.67.2
v1.67.1
v1.67.0
v1.66.1
v1.66.0
v1.65.0
v1.64.0
v1.63.2
v1.63.1
v1.63.0
v1.62.1
v1.62.0
v1.61.0
v1.60.0
v1.59.1
v1.59.0
v1.58.0
v1.57.1
v1.57.0
v1.56.2
v1.56.1
v1.56.0
v1.55.1
v1.55.0
v1.54.1
v1.54.0
v1.53.0
v1.52.1
v1.52.0
v1.51.2
v1.51.1
v1.51.0
v1.50.1
v1.50.0
v1.49.0
v1.48.1
v1.48.0
v1.47.3
v1.47.2
v1.47.1
v1.47.0
v1.46.1
v1.46.0
v1.45.0
v1.44.0
v1.43.1
v1.43.0
v1.42.0_65-dev
v1.41.1_64-dev
v1.41.0_64-dev
v1.40.1_63-dev
v1.40.0_63-dev
v1.39.0_61-dev
v1.38.2_60-dev
v1.38.1_60-dev
v1.38.0_60-dev
v1.37.0_58-dev
v1.36.2_56-dev
v1.36.1_55-dev
v1.36.0_55-dev
v1.35.0_54-dev
v1.34.0_53-dev
v1.33.1_52-dev
v1.33.0_52-dev
v1.32.1_51-dev
v1.32.0_50-dev
v1.31.1_49-dev
v1.31.0_49-dev
v1.30.2_48-dev
v1.30.0_46-dev
v1.29.6_45-dev
v1.29.6_44-dev
v1.29.5_44-dev
v1.29.4_44-dev
v1.29.3_43-dev
v1.29.2_43-dev
v1.29.1_43-dev
v1.29.0_42-dev
v1.28.4_41-dev
v1.28.4_42-dev
v1.28.3_41-dev
v1.28.2_40-dev
v1.28.1_39-dev
v1.28.0_38-dev
v1.27.0_37-dev
v1.26.0_36-dev
v1.25.0_35-dev
v1.24.0_34-dev
v1.23.0_33-dev
v1.22.0_32-dev
v1.21.1_31-dev
v1.21.0_31-dev
v1.20.3_30-dev
v1.20.2_30-dev
v1.20.1_30-dev
v1.20.0_30-dev
v1.19.1_29-dev
v1.19.0_29-dev
v1.18.0_27-dev
v1.17.0_25-dev
v1.16.0_23-dev
v1.15.1_21-dev
v1.15.0_21-dev
v1.14.0_21-dev
v1.13.0_20-dev
v1.12.0_18-dev
v1.11.0_17-dev
v1.10.0_15-dev
v1.9.1_14-dev
v1.9.0_13-dev
v1.8.0_12-dev
v1.7.0_11-dev
v1.6.0_10-dev
v1.5.1+9-dev
v1.5.0+8-dev
v1.4.0+7-dev
v1.4.0+6-dev
v1.4.0-dev
v1.3.0-dev
v1.3.1-dev
v0.6-dev
v0.5-dev
v0.4-dev
v0.3-dev
v0.2-dev
first-android-release
Labels
Clear labels
accessibility
changelog:enhancement
changelog:security
changelog:skip
changelog:translation
cli
date-time
dependencies
documentation
external-library
format
good first issue
mobile-beta
mobile-beta
mobile-beta
needs-answer
nice to have
pull-request
sharing
tech-debt
📱mobile
🖥️web
🗄️server
🧠machine-learning
Mirrored from GitHub Pull Request
No Label
Milestone
No items
No Milestone
Projects
Clear projects
No project
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: immich-app/immich#2174
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mingqlin on GitHub (Feb 17, 2024).
The bug
Love Immich
I have 800,000+ Photos and Videos, but the performance is unusable. Mobile app never able to finish "Building the timeline". It appears this query takes too long. My Unraid server are Intel 13th Gen I7. I run query manually, following query take 1 to 2 second to finish. I hope all database query should be optimized
The OS that Immich Server is running on
Unraid
Version of Immich Server
v1.94.1
Version of Immich Mobile App
v1.94.1
Platform with the issue
Your docker-compose.yml content
Your .env content
Reproduction steps
Additional information
No response
@bo0tzz commented on GitHub (Feb 17, 2024):
How is the performance on the web client?
@mingqlin commented on GitHub (Feb 17, 2024):
Moving cursor on the right vertical timeline, freeze up the browser most of the time. Initial loading is ok (when open the "Photos" page), but when click on timeline (vertical to the right), the browser freeze up
@mingqlin commented on GitHub (Feb 17, 2024):
try run "ALTER DATABASE immich SET log_min_duration_statement = 500;" and the console log will show all query taking too long
@mingqlin commented on GitHub (Feb 17, 2024):
Above is sequencial scan report
@mingqlin commented on GitHub (Feb 17, 2024):
Running android mobile app (on XiaoMi 13T Pro), "Building the timeline" on my 1GB LAN from Immich Server running on Unraid (Intel I7 13Gen), my sync data transfer is less than 2MB/s, most of time just idle, I hope the sync could be much faster. I remember before than paging change, transfer stay constant some faster than 8MB/s
This time snapshot shows how long it takes to go from OFFSET 320000 to OFFSET 820000, it took 9 minutes. The worst part is after the "Building the timeline" is completed, only small amount of photo/videos (less than 50) are show up on my app, after pull down to refresh, the "Building the timeline" start all over again
LIMIT 5000 OFFSET 320000
2024-02-17 08:01:04.672
LIMIT 5000 OFFSET 335000
2024-02-17 08:01:14.664
LIMIT 5000 OFFSET 425000
2024-02-17 08:02:31.085 PST
LIMIT 5000 OFFSET 550000
2024-02-17 08:04:42.475 PST
LIMIT 5000 OFFSET 625000
2024-02-17 08:06:12.399 PST
ASC LIMIT 5000 OFFSET 820000
2024-02-17 08:10:09.525
@alextran1502 commented on GitHub (Feb 17, 2024):
Thank you for the report. This is very useful as we haven't been able to setup an instance with this many assets yet ❤️
@mingqlin commented on GitHub (Feb 17, 2024):
Thank you, Alex and the team, amazing work!!
@mertalev commented on GitHub (Feb 18, 2024):
Would you be able to add
EXPLAIN ANALYZEto the start of this query and show the query plan? That would help narrow down the slowest part of the query.@mingqlin commented on GitHub (Feb 18, 2024):
Thank you @mertalev for looking into this issue.
Below is query:
EXPLAIN ANALYZE SELECT DISTINCT "distinctAlias"."AssetEntity_id" AS "ids_AssetEntity_id", "distinctAlias"."AssetEntity_fileCreatedAt" FROM (SELECT "AssetEntity"."id" AS "AssetEntity_id", "AssetEntity"."deviceAssetId" AS "AssetEntity_deviceAssetId", "AssetEntity"."ownerId" AS "AssetEntity_ownerId", "AssetEntity"."libraryId" AS "AssetEntity_libraryId", "AssetEntity"."deviceId" AS "AssetEntity_deviceId", "AssetEntity"."type" AS "AssetEntity_type", "AssetEntity"."originalPath" AS "AssetEntity_originalPath", "AssetEntity"."resizePath" AS "AssetEntity_resizePath", "AssetEntity"."webpPath" AS "AssetEntity_webpPath", "AssetEntity"."thumbhash" AS "AssetEntity_thumbhash", "AssetEntity"."encodedVideoPath" AS "AssetEntity_encodedVideoPath", "AssetEntity"."createdAt" AS "AssetEntity_createdAt", "AssetEntity"."updatedAt" AS "AssetEntity_updatedAt", "AssetEntity"."deletedAt" AS "AssetEntity_deletedAt", "AssetEntity"."fileCreatedAt" AS "AssetEntity_fileCreatedAt", "AssetEntity"."localDateTime" AS "AssetEntity_localDateTime", "AssetEntity"."fileModifiedAt" AS "AssetEntity_fileModifiedAt", "AssetEntity"."isFavorite" AS "AssetEntity_isFavorite", "AssetEntity"."isArchived" AS "AssetEntity_isArchived", "AssetEntity"."isExternal" AS "AssetEntity_isExternal", "AssetEntity"."isReadOnly" AS "AssetEntity_isReadOnly", "AssetEntity"."isOffline" AS "AssetEntity_isOffline", "AssetEntity"."checksum" AS "AssetEntity_checksum", "AssetEntity"."duration" AS "AssetEntity_duration", "AssetEntity"."isVisible" AS "AssetEntity_isVisible", "AssetEntity"."livePhotoVideoId" AS "AssetEntity_livePhotoVideoId", "AssetEntity"."originalFileName" AS "AssetEntity_originalFileName", "AssetEntity"."sidecarPath" AS "AssetEntity_sidecarPath", "AssetEntity"."stackId" AS "AssetEntity_stackId", "AssetEntity__AssetEntity_exifInfo"."assetId" AS "AssetEntity__AssetEntity_exifInfo_assetId", "AssetEntity__AssetEntity_exifInfo"."description" AS "AssetEntity__AssetEntity_exifInfo_description", "AssetEntity__AssetEntity_exifInfo"."exifImageWidth" AS "AssetEntity__AssetEntity_exifInfo_exifImageWidth", "AssetEntity__AssetEntity_exifInfo"."exifImageHeight" AS "AssetEntity__AssetEntity_exifInfo_exifImageHeight", "AssetEntity__AssetEntity_exifInfo"."fileSizeInByte" AS "AssetEntity__AssetEntity_exifInfo_fileSizeInByte", "AssetEntity__AssetEntity_exifInfo"."orientation" AS "AssetEntity__AssetEntity_exifInfo_orientation", "AssetEntity__AssetEntity_exifInfo"."dateTimeOriginal" AS "AssetEntity__AssetEntity_exifInfo_dateTimeOriginal", "AssetEntity__AssetEntity_exifInfo"."modifyDate" AS "AssetEntity__AssetEntity_exifInfo_modifyDate", "AssetEntity__AssetEntity_exifInfo"."timeZone" AS "AssetEntity__AssetEntity_exifInfo_timeZone", "AssetEntity__AssetEntity_exifInfo"."latitude" AS "AssetEntity__AssetEntity_exifInfo_latitude", "AssetEntity__AssetEntity_exifInfo"."longitude" AS "AssetEntity__AssetEntity_exifInfo_longitude", "AssetEntity__AssetEntity_exifInfo"."projectionType" AS "AssetEntity__AssetEntity_exifInfo_projectionType", "AssetEntity__AssetEntity_exifInfo"."city" AS "AssetEntity__AssetEntity_exifInfo_city", "AssetEntity__AssetEntity_exifInfo"."livePhotoCID" AS "AssetEntity__AssetEntity_exifInfo_livePhotoCID", "AssetEntity__AssetEntity_exifInfo"."autoStackId" AS "AssetEntity__AssetEntity_exifInfo_autoStackId", "AssetEntity__AssetEntity_exifInfo"."state" AS "AssetEntity__AssetEntity_exifInfo_state", "AssetEntity__AssetEntity_exifInfo"."country" AS "AssetEntity__AssetEntity_exifInfo_country", "AssetEntity__AssetEntity_exifInfo"."make" AS "AssetEntity__AssetEntity_exifInfo_make", "AssetEntity__AssetEntity_exifInfo"."model" AS "AssetEntity__AssetEntity_exifInfo_model", "AssetEntity__AssetEntity_exifInfo"."lensModel" AS "AssetEntity__AssetEntity_exifInfo_lensModel", "AssetEntity__AssetEntity_exifInfo"."fNumber" AS "AssetEntity__AssetEntity_exifInfo_fNumber", "AssetEntity__AssetEntity_exifInfo"."focalLength" AS "AssetEntity__AssetEntity_exifInfo_focalLength", "AssetEntity__AssetEntity_exifInfo"."iso" AS "AssetEntity__AssetEntity_exifInfo_iso", "AssetEntity__AssetEntity_exifInfo"."exposureTime" AS "AssetEntity__AssetEntity_exifInfo_exposureTime", "AssetEntity__AssetEntity_exifInfo"."profileDescription" AS "AssetEntity__AssetEntity_exifInfo_profileDescription", "AssetEntity__AssetEntity_exifInfo"."colorspace" AS "AssetEntity__AssetEntity_exifInfo_colorspace", "AssetEntity__AssetEntity_exifInfo"."bitsPerSample" AS "AssetEntity__AssetEntity_exifInfo_bitsPerSample", "AssetEntity__AssetEntity_exifInfo"."fps" AS "AssetEntity__AssetEntity_exifInfo_fps", "AssetEntity__AssetEntity_tags"."id" AS "AssetEntity__AssetEntity_tags_id", "AssetEntity__AssetEntity_tags"."type" AS "AssetEntity__AssetEntity_tags_type", "AssetEntity__AssetEntity_tags"."name" AS "AssetEntity__AssetEntity_tags_name", "AssetEntity__AssetEntity_tags"."userId" AS "AssetEntity__AssetEntity_tags_userId", "AssetEntity__AssetEntity_tags"."renameTagId" AS "AssetEntity__AssetEntity_tags_renameTagId", "AssetEntity__AssetEntity_stack"."id" AS "AssetEntity__AssetEntity_stack_id", "AssetEntity__AssetEntity_stack"."primaryAssetId" AS "AssetEntity__AssetEntity_stack_primaryAssetId", "bd93d5747511a4dad4923546c51365bf1a803774"."id" AS "bd93d5747511a4dad4923546c51365bf1a803774_id", "bd93d5747511a4dad4923546c51365bf1a803774"."deviceAssetId" AS "bd93d5747511a4dad4923546c51365bf1a803774_deviceAssetId", "bd93d5747511a4dad4923546c51365bf1a803774"."ownerId" AS "bd93d5747511a4dad4923546c51365bf1a803774_ownerId", "bd93d5747511a4dad4923546c51365bf1a803774"."libraryId" AS "bd93d5747511a4dad4923546c51365bf1a803774_libraryId", "bd93d5747511a4dad4923546c51365bf1a803774"."deviceId" AS "bd93d5747511a4dad4923546c51365bf1a803774_deviceId", "bd93d5747511a4dad4923546c51365bf1a803774"."type" AS "bd93d5747511a4dad4923546c51365bf1a803774_type", "bd93d5747511a4dad4923546c51365bf1a803774"."originalPath" AS "bd93d5747511a4dad4923546c51365bf1a803774_originalPath", "bd93d5747511a4dad4923546c51365bf1a803774"."resizePath" AS "bd93d5747511a4dad4923546c51365bf1a803774_resizePath", "bd93d5747511a4dad4923546c51365bf1a803774"."webpPath" AS "bd93d5747511a4dad4923546c51365bf1a803774_webpPath", "bd93d5747511a4dad4923546c51365bf1a803774"."thumbhash" AS "bd93d5747511a4dad4923546c51365bf1a803774_thumbhash", "bd93d5747511a4dad4923546c51365bf1a803774"."encodedVideoPath" AS "bd93d5747511a4dad4923546c51365bf1a803774_encodedVideoPath", "bd93d5747511a4dad4923546c51365bf1a803774"."createdAt" AS "bd93d5747511a4dad4923546c51365bf1a803774_createdAt", "bd93d5747511a4dad4923546c51365bf1a803774"."updatedAt" AS "bd93d5747511a4dad4923546c51365bf1a803774_updatedAt", "bd93d5747511a4dad4923546c51365bf1a803774"."deletedAt" AS "bd93d5747511a4dad4923546c51365bf1a803774_deletedAt", "bd93d5747511a4dad4923546c51365bf1a803774"."fileCreatedAt" AS "bd93d5747511a4dad4923546c51365bf1a803774_fileCreatedAt", "bd93d5747511a4dad4923546c51365bf1a803774"."localDateTime" AS "bd93d5747511a4dad4923546c51365bf1a803774_localDateTime", "bd93d5747511a4dad4923546c51365bf1a803774"."fileModifiedAt" AS "bd93d5747511a4dad4923546c51365bf1a803774_fileModifiedAt", "bd93d5747511a4dad4923546c51365bf1a803774"."isFavorite" AS "bd93d5747511a4dad4923546c51365bf1a803774_isFavorite", "bd93d5747511a4dad4923546c51365bf1a803774"."isArchived" AS "bd93d5747511a4dad4923546c51365bf1a803774_isArchived", "bd93d5747511a4dad4923546c51365bf1a803774"."isExternal" AS "bd93d5747511a4dad4923546c51365bf1a803774_isExternal", "bd93d5747511a4dad4923546c51365bf1a803774"."isReadOnly" AS "bd93d5747511a4dad4923546c51365bf1a803774_isReadOnly", "bd93d5747511a4dad4923546c51365bf1a803774"."isOffline" AS "bd93d5747511a4dad4923546c51365bf1a803774_isOffline", "bd93d5747511a4dad4923546c51365bf1a803774"."checksum" AS "bd93d5747511a4dad4923546c51365bf1a803774_checksum", "bd93d5747511a4dad4923546c51365bf1a803774"."duration" AS "bd93d5747511a4dad4923546c51365bf1a803774_duration", "bd93d5747511a4dad4923546c51365bf1a803774"."isVisible" AS "bd93d5747511a4dad4923546c51365bf1a803774_isVisible", "bd93d5747511a4dad4923546c51365bf1a803774"."livePhotoVideoId" AS "bd93d5747511a4dad4923546c51365bf1a803774_livePhotoVideoId", "bd93d5747511a4dad4923546c51365bf1a803774"."originalFileName" AS "bd93d5747511a4dad4923546c51365bf1a803774_originalFileName", "bd93d5747511a4dad4923546c51365bf1a803774"."sidecarPath" AS "bd93d5747511a4dad4923546c51365bf1a803774_sidecarPath", "bd93d5747511a4dad4923546c51365bf1a803774"."stackId" AS "bd93d5747511a4dad4923546c51365bf1a803774_stackId" FROM "assets" "AssetEntity" LEFT JOIN "exif" "AssetEntity__AssetEntity_exifInfo" ON "AssetEntity__AssetEntity_exifInfo"."assetId" = "AssetEntity"."id" LEFT JOIN "tag_asset" "AssetEntity_AssetEntity__AssetEntity_tags" ON "AssetEntity_AssetEntity__AssetEntity_tags"."assetsId" = "AssetEntity"."id" LEFT JOIN "tags" "AssetEntity__AssetEntity_tags" ON "AssetEntity__AssetEntity_tags"."id" = "AssetEntity_AssetEntity__AssetEntity_tags"."tagsId" LEFT JOIN "asset_stack" "AssetEntity__AssetEntity_stack" ON "AssetEntity__AssetEntity_stack"."id" = "AssetEntity"."stackId" LEFT JOIN "assets" "bd93d5747511a4dad4923546c51365bf1a803774" ON "bd93d5747511a4dad4923546c51365bf1a803774"."stackId" = "AssetEntity__AssetEntity_stack"."id" WHERE ("AssetEntity"."ownerId" = 'c8247244-cb7e-405d-970c-6bf5c34a8cb3' AND "AssetEntity"."isVisible" = 't' AND "AssetEntity"."updatedAt" <= '2024-02-17 07:14:14.296-08')) "distinctAlias" ORDER BY "distinctAlias"."AssetEntity_fileCreatedAt" DESC, "AssetEntity_id" ASC LIMIT 5000 OFFSET 215000This is the result:
Limit (cost=236820.22..237427.55 rows=5000 width=24) (actual time=967.281..1030.582 rows=5000 loops=1) -> Unique (cost=210704.92..310837.64 rows=824365 width=24) (actual time=893.274..999.371 rows=220000 loops=1) -> Gather Merge (cost=210704.92..306715.81 rows=824365 width=24) (actual time=893.264..987.952 rows=220000 loops=1) Workers Planned: 2 Workers Launched: 2 -> Sort (cost=209704.90..210563.61 rows=343485 width=24) (actual time=823.161..833.805 rows=74101 loops=3) " Sort Key: ""AssetEntity"".""fileCreatedAt"" DESC, ""AssetEntity"".id" Sort Method: external merge Disk: 9032kB Worker 0: Sort Method: external merge Disk: 9208kB Worker 1: Sort Method: external merge Disk: 9240kB -> Merge Left Join (cost=169346.25..171076.15 rows=343485 width=24) (actual time=588.474..639.898 rows=274201 loops=3) " Merge Cond: (""AssetEntity"".id = ""AssetEntity_AssetEntity__AssetEntity_tags"".""assetsId"")" -> Sort (cost=169251.87..170110.58 rows=343485 width=24) (actual time=588.093..627.491 rows=274201 loops=3) " Sort Key: ""AssetEntity"".id" Sort Method: external merge Disk: 9032kB Worker 0: Sort Method: external merge Disk: 9208kB Worker 1: Sort Method: external merge Disk: 9240kB -> Hash Left Join (cost=67324.24..130623.12 rows=343485 width=24) (actual time=15.583..423.047 rows=274201 loops=3) " Hash Cond: (""AssetEntity"".""stackId"" = ""AssetEntity__AssetEntity_stack"".id)" " -> Parallel Seq Scan on assets ""AssetEntity"" (cost=0.00..62010.79 rows=343485 width=40) (actual time=14.930..405.618 rows=274201 loops=3)" " Filter: (""isVisible"" AND (""updatedAt"" <= '2024-02-17 15:14:14.296+00'::timestamp with time zone) AND (""ownerId"" = 'c8247244-cb7e-405d-970c-6bf5c34a8cb3'::uuid))" Rows Removed by Filter: 431 -> Hash (cost=67307.24..67307.24 rows=1360 width=16) (actual time=0.110..0.127 rows=0 loops=3) Buckets: 2048 Batches: 1 Memory Usage: 16kB -> Hash Right Join (cost=40.60..67307.24 rows=1360 width=16) (actual time=0.106..0.118 rows=0 loops=3) " Hash Cond: (bd93d5747511a4dad4923546c51365bf1a803774.""stackId"" = ""AssetEntity__AssetEntity_stack"".id)" -> Seq Scan on assets bd93d5747511a4dad4923546c51365bf1a803774 (cost=0.00..65102.47 rows=824447 width=16) (never executed) -> Hash (cost=23.60..23.60 rows=1360 width=16) (actual time=0.092..0.097 rows=0 loops=3) Buckets: 2048 Batches: 1 Memory Usage: 16kB " -> Seq Scan on asset_stack ""AssetEntity__AssetEntity_stack"" (cost=0.00..23.60 rows=1360 width=16) (actual time=0.091..0.092 rows=0 loops=3)" -> Sort (cost=94.38..97.78 rows=1360 width=32) (actual time=0.185..0.190 rows=0 loops=3) " Sort Key: ""AssetEntity_AssetEntity__AssetEntity_tags"".""assetsId""" Sort Method: quicksort Memory: 25kB Worker 0: Sort Method: quicksort Memory: 25kB Worker 1: Sort Method: quicksort Memory: 25kB " -> Seq Scan on tag_asset ""AssetEntity_AssetEntity__AssetEntity_tags"" (cost=0.00..23.60 rows=1360 width=32) (actual time=0.120..0.122 rows=0 loops=3)" Planning Time: 4.352 ms JIT: Functions: 78 " Options: Inlining false, Optimization false, Expressions true, Deforming true" " Timing: Generation 6.218 ms, Inlining 0.000 ms, Optimization 7.933 ms, Emission 65.082 ms, Total 79.233 ms" Execution Time: 1586.561 msScreenshot of the result, you can see it takes 1s 613ms

@mertalev commented on GitHub (Feb 18, 2024):
It looks to me like the slowest parts are the filtering for
isVisibleandupdatedAtand getting distinct rows. The former is a parallel seq scan and the latter adds a gather merge to the query.@mertalev commented on GitHub (Feb 18, 2024):
It looks like this query is a lot more complex than it needs to be. It ultimately just returns
idandfileCreatedAt, so not only is the subquery full of joins pointless, the DISTINCT has to deduplicate all of those rows.fileCreatedAtalso doesn't have an index, so ordering by this forces a table scan.Lastly, since pagination is implemented with LIMIT/OFFSET, the query is executed many many times since the mobile app fetches each page during sync. This part is harder to optimize, but the query being faster should still help a lot.
Can you run this to compare the performance?
@mingqlin commented on GitHub (Feb 18, 2024):
I have a correction, After shutdown all my Unraid Immich background jobs (this morning videos encoding background job was running.)
Original query take about average ~300ms
New query table about average ~165ms (The index "idx_asset_file_created_at" make no difference, I run query before and after create index, don't see any performance difference)
This is EXPLAIN ANALYZE:
EXPLAIN ANALYZE SELECT "AssetEntity"."id" AS "AssetEntity_id", "AssetEntity"."fileCreatedAt" AS "AssetEntity_fileCreatedAt" FROM "assets" "AssetEntity" WHERE "AssetEntity"."ownerId" = 'c8247244-cb7e-405d-970c-6bf5c34a8cb3' AND "AssetEntity"."isVisible" = 't' AND "AssetEntity"."updatedAt" <= '2024-02-17 07:14:14.296-08' ORDER BY "AssetEntity_fileCreatedAt" DESC, "AssetEntity_id" ASC LIMIT 5000 OFFSET 210000;Result:
Limit (cost=66490.29..68073.35 rows=5000 width=24) (actual time=121.279..124.602 rows=5000 loops=1) -> Incremental Sort (cost=1.68..260831.42 rows=823814 width=24) (actual time=0.081..121.962 rows=215000 loops=1) " Sort Key: ""fileCreatedAt"" DESC, id" " Presorted Key: ""fileCreatedAt""" Full-sort Groups: 6299 Sort Method: quicksort Average Memory: 27kB Peak Memory: 27kB Pre-sorted Groups: 48 Sort Method: quicksort Average Memory: 25kB Peak Memory: 25kB " -> Index Scan Backward using idx_asset_file_created_at on assets ""AssetEntity"" (cost=0.42..229153.94 rows=823814 width=24) (actual time=0.029..98.880 rows=215011 loops=1)" " Filter: (""isVisible"" AND (""updatedAt"" <= '2024-02-17 15:14:14.296+00'::timestamp with time zone) AND (""ownerId"" = 'c8247244-cb7e-405d-970c-6bf5c34a8cb3'::uuid))" Rows Removed by Filter: 1982 Planning Time: 0.069 ms Execution Time: 124.682 ms@mertalev commented on GitHub (Feb 18, 2024):
That's interesting, it was still doing a seq scan for me until I added the index so I'd expect it to make a difference.
Overall though I think this is probably the best this query's going to get until we switch to cursor-based pagination. Switching to that would mean instead of running the query each time to get the next page, the query just continues from where it left off.
@mingqlin commented on GitHub (Feb 18, 2024):
I am doing complete "Building the timeline", I uninstalled the Immich Android app, reinstall the latest [v1.94.1], login
1. Log every SQL query attached (Start from Login, until I stop video recording recording)
postgresql15-2024-02-18T03-39-02.zip
2. Video recording of the android "Build the timeline" (record start right after login)
https://youtu.be/yuue0A5zp60
3. Check the Android Immich app log:

Android app Error log Detail:
`
MESSAGE
Error while getting remote assets: ApiException 400: HTTP connection failed: GET /asset (Inner exception: Connection closed before full header was received)
#0 IOClient.send (package:http/src/io_client.dart:90)
#1 BaseClient._sendUnstreamed (package:http/src/base_client.dart:93)
#2 ApiClient.invokeAPI (package:openapi/api_client.dart:101)
#3 AssetApi.getAllAssets (package:openapi/api/asset_api.dart:400)
#4 AssetService._getRemoteAssets (package:immich_mobile/shared/services/asset.service.dart:72)
#5 SyncService._syncRemoteAssetsFull (package:immich_mobile/shared/services/sync.service.dart:209)
#6 SyncService.syncRemoteAssetsToDb. (package:immich_mobile/shared/services/sync.service.dart:53)
#7 AsyncMutex.run. (package:immich_mobile/utils/async_mutex.dart:15)
FROM
AssetService
Stack TRACES
#0 ApiClient.invokeAPI (package:openapi/api_client.dart:125)
#1 AssetApi.getAllAssets (package:openapi/api/asset_api.dart:400)
#2 AssetService._getRemoteAssets (package:immich_mobile/shared/services/asset.service.dart:72)
#3 SyncService._syncRemoteAssetsFull (package:immich_mobile/shared/services/sync.service.dart:209)
#4 SyncService.syncRemoteAssetsToDb. (package:immich_mobile/shared/services/sync.service.dart:53)
#5 AsyncMutex.run. (package:immich_mobile/utils/async_mutex.dart:15)
`
I hope from the SQL query log, you can find more problems with the database query
From the video recording, you could see the KB/s or MB/s of network speed at the top of the screen, the network goes idle after a couple of minutes, but "Building the timeline" never stops
@mertalev commented on GitHub (Feb 18, 2024):
I'm not very familiar with how the app sync works, but it might be fetching 5000 IDs (with the query you posted) and querying the server for the assets of those IDs.
@mertalev commented on GitHub (Feb 18, 2024):
Also thanks for sharing the query logs! That will be very helpful
@mertalev commented on GitHub (Feb 18, 2024):
Oh, I think this is actually something the ORM is doing. It gets the IDs with one query and does a second query for the other fields.
@mingqlin commented on GitHub (Feb 18, 2024):
More error log reported by Android App

@mingqlin commented on GitHub (Feb 18, 2024):
IF ORM is doing from Client app, it is very large query data need to send over the network. I hope there is way to optimize it, since the same ID was return from the paging, any additinal data, should be query along the first paging and send over the network at the same time, to prevent secondary query by giving it all 5000 IDs back to the server (which just returned from the server).
Sorry, I am very new to Immich library, but I do a programmer, some of the things I say, may not be accurate
@mertalev commented on GitHub (Feb 18, 2024):
Oh wow. I don't know anything about Isar (the local database in the app), so maybe one of the mobile devs can comment on what's happening there.
The new query won't have this issue since it gets all the data in one pass.
@mingqlin commented on GitHub (Feb 18, 2024):
For the Flutter developer, please check out this link, it may explain about the Isar DB Full exception, and possible solution:
https://github.com/isar/isar/issues/813
@mertalev commented on GitHub (Feb 18, 2024):
Thanks for the link! I think the way the mobile app syncs is by fetching all the assets from all pages before adding them to the local DB. With a large number of assets, this is probably too much for the database to handle in one transaction. Syncing one page at a time should avoid this issue.
@mingqlin commented on GitHub (Feb 18, 2024):
800,000 Assets need to Isar upsert 800,000/5000 = 160 times, If Isar 160 write is a performance issue, please consider adjusting 5000 per page, maybe increase it to 10000, or even higher. Not sure how 5000 per page was decided
@mertalev commented on GitHub (Feb 18, 2024):
We should be able to increase it. That would also help with the fact that the query is run for each page: a page of 10000 reduces the number of queries from 160 to 80.
@mingqlin commented on GitHub (Feb 18, 2024):
Google Chrome Browser and Microsft Edge Web Browser, clicking on the timeline (jump to different date) will freeze up the browser, I couldn't find any log to help fixing this issue. I hope developer could find a way to test with 1M+ assets Immich server to reproduce this issue
@mertalev commented on GitHub (Feb 18, 2024):
We're planning on adding OpenTelemetry integration throughout the server in the future. That will make it easier to identify these kinds of performance issues.