Unity-Technologies / Unity-Technologies/UnityDataTools

Handler Finalize() methods are never called, so intended indexes are never created

Open
#83 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
821
Forks
71
Avg merge
3h 13m
Merged PRs (30d)
9

Description

Summary

The ISQLiteHandler implementations each define a public void Finalize(SqliteConnection db) method, but nothing ever calls it. Finalize is not part of the ISQLiteHandler interface (which only declares Init, Process, and Dispose), and there is no dispatch site anywhere in the codebase. As a result, the finalization work in those methods never runs.

For most handlers the method is an empty stub, but two of them create indexes that are therefore never created:

  • AssetBundleHandler.Finalize -> preload_dependencies_object, preload_dependencies_dependency
  • ShaderHandler.Finalize -> shader_subprograms_shader_index, shader_subprogram_keywords_subprogram_id_index

(Note: SQLiteWriter.End() runs Resources.Finalize / Finalize.sql, which creates the refs indexes. That is a separate, top-level mechanism and does run - it is unrelated to these per-handler Finalize methods.)

Impact

  • The four indexes above are missing from every analyze database, so queries that filter/join on preload_dependencies(object), preload_dependencies(dependency), shader_subprograms(shader), and shader_subprogram_keywords(subprogram_id) do full scans. This is a performance issue only; results are still correct.
  • The empty Finalize stubs in the other handlers are dead code and misleadingly imply a finalization step exists.

Evidence

After running analyze on TestCommon/Data/LeadingEdgeBuilds/AssetBundles:

sqlite> SELECT name FROM sqlite_master WHERE type='index' AND name LIKE 'preload_%';
-- (no rows)

The preload_dependencies table and its data are present, but the indexes are not.

Affected files

  • Analyzer/SQLite/Handlers/ISQLiteHandler.cs - interface has no Finalize.
  • Non-empty bodies: Analyzer/SQLite/Handlers/AssetBundleHandler.cs, Analyzer/SQLite/Handlers/ShaderHandler.cs.
  • Empty stubs: AnimationClipHandler.cs, AudioClipHandler.cs, BuildReportHandler.cs, MeshHandler.cs, MonoScriptHandler.cs, PackedAssetsHandler.cs, PreloadDataHandler.cs, Texture2DHandler.cs.

Suggested fix

Either:

  1. Wire it up - add Finalize(SqliteConnection db) to ISQLiteHandler and invoke it once per handler after all serialized files are processed (the handler lifecycle is owned by SerializedFileSQLiteWriter; SQLiteWriter.End() is the natural point at which finalization runs). Drop the now-redundant empty overrides where possible. This restores the four intended indexes.

  2. Delete the dead code - if the indexes are not wanted, remove all the Finalize methods.

Option 1 is preferred since the indexes are clearly intended and benefit lookups on the dependency and shader-subprogram tables.

Notes

The two preload_dependencies_* index names were just updated in #82 (table rename); this bug predates that change - the indexes were never created under their old asset_dependencies_* names either.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Analyzer/SQLite/Handlers/ISQLiteHandler.cs and the handler lifecycle in SerializedFileSQLiteWriter; inspect SQLiteWriter.End() as the proposed finalization entry point. Trace how handlers are processed, then verify completion by checking that the four intended indexes appear in the analyze database and that obsolete empty stubs are handled consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sqlite
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.