Skip to content

Commit 33fcf4a

Browse files
[#82] Rename assets/asset_dependencies tables to reflect AssetBundle/PreloadData origin (#84)
* [#82] Rename assets/preload_dependencies tables to reflect their origin Rename the vaguely-named assets and asset_dependencies tables (and their views) so it is clear they are populated from the AssetBundle and PreloadData objects and are mostly empty for Player/ContentDirectory builds: assets -> assetbundle_assets asset_view -> assetbundle_asset_view asset_dependencies -> preload_dependencies asset_dependencies_view -> preload_dependencies_view Bumps the schema user_version 1 -> 2 and raises find-refs' RequiredSchemaVersion to match, since the renamed tables it queries make older databases unreadable.
1 parent 1438138 commit 33fcf4a

12 files changed

Lines changed: 48 additions & 46 deletions

File tree

Analyzer/Resources/AssetBundle.sql

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
-- the AssetBundle object, so this table is empty for Player and ContentDirectory builds.
99
-- For scene bundles the entry names the scene and points at the synthetic Scene object (see
1010
-- AssetBundleHandler / SerializedFileSQLiteWriter).
11-
CREATE TABLE IF NOT EXISTS assets(
11+
CREATE TABLE IF NOT EXISTS assetbundle_assets(
1212
object INTEGER,
1313
name TEXT
1414
);
@@ -18,22 +18,22 @@ CREATE TABLE IF NOT EXISTS assets(
1818
-- * AssetBundleHandler: an asset's slice of the AssetBundle object's m_PreloadTable.
1919
-- * SerializedFileSQLiteWriter: a scene object -> each object in the scene's SerializedFiles.
2020
-- * PreloadDataHandler: the PreloadData object's m_Assets. PreloadData is a *separate* Unity
21-
-- object (not part of the AssetBundle object) and also exists in Player builds, so this table
22-
-- is NOT empty there; but those builds have no scene object, so PreloadDataHandler currently
23-
-- attributes the rows to object id -1 (a known limitation).
24-
CREATE TABLE IF NOT EXISTS asset_dependencies(
21+
-- object (not part of the AssetBundle object) and also exists in Player builds (one per scene in its sharedAsset file),
22+
-- so this table is NOT empty there; but those builds have no scene object, so PreloadDataHandler currently
23+
-- attributes the rows to object id -1 (issue 81).
24+
CREATE TABLE IF NOT EXISTS preload_dependencies(
2525
object INTEGER,
2626
dependency INTEGER
2727
);
2828

29-
CREATE VIEW IF NOT EXISTS asset_view AS
29+
CREATE VIEW IF NOT EXISTS assetbundle_asset_view AS
3030
SELECT
3131
a.name AS asset_name,
3232
o.*
33-
FROM assets a INNER JOIN object_view o ON o.id = a.object;
33+
FROM assetbundle_assets a INNER JOIN object_view o ON o.id = a.object;
3434

35-
CREATE VIEW IF NOT EXISTS asset_dependencies_view AS
35+
CREATE VIEW IF NOT EXISTS preload_dependencies_view AS
3636
SELECT a.id, a.asset_name, a.asset_bundle, a.type, od.id dep_id, od.asset_bundle dep_asset_bundle, od.name dep_name, od.type dep_type
37-
FROM asset_view a
38-
INNER JOIN asset_dependencies d ON a.id = d.object
37+
FROM assetbundle_asset_view a
38+
INNER JOIN preload_dependencies d ON a.id = d.object
3939
INNER JOIN object_view od ON od.id = d.dependency;

Analyzer/Resources/Init.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ SELECT m.id material_id, m.name material_name, a.name material_path, m.asset_bun
139139
FROM object_view m
140140
INNER JOIN refs_view r ON m.id = r.object AND r.property_path = 'm_Shader'
141141
INNER JOIN object_view s ON r.referenced_object = s.id
142-
LEFT JOIN assets a ON m.id = a.object;
142+
LEFT JOIN assetbundle_assets a ON m.id = a.object;
143143

144144
CREATE VIEW view_material_texture_refs AS
145145
SELECT m.id material_id, m.name material_name, a.name material_path, m.asset_bundle material_asset_bundle, t.id texture_id, t.name texture_name, t.asset_bundle texture_asset_bundle
146146
FROM object_view m
147147
INNER JOIN refs_view r ON r.object = m.id AND property_type = 'Texture'
148148
INNER JOIN object_view t ON r.referenced_object = t.id
149-
LEFT JOIN assets a ON m.id = a.object
149+
LEFT JOIN assetbundle_assets a ON m.id = a.object
150150
WHERE m.type = 'Material';
151151

152152
-- Special-case type value for the fake Scene object that is sometimes inserted into the object table,
@@ -155,8 +155,9 @@ INSERT INTO types (id, name) VALUES (-1, 'Scene');
155155

156156
-- Database schema version. Bump when the schema changes in a way that tools relying on it
157157
-- (e.g. find-refs) cannot read from an older database. 1 = normalized refs table (issue #44);
158-
-- databases produced before versioning report 0.
159-
PRAGMA user_version = 1;
158+
-- 2 = renamed assets/asset_dependencies tables to assetbundle_assets/preload_dependencies
159+
-- (issue #82); databases produced before versioning report 0.
160+
PRAGMA user_version = 2;
160161

161162
PRAGMA synchronous = OFF;
162163
PRAGMA journal_mode = MEMORY;

Analyzer/SQLite/Commands/SerializedFile/AddAssetDependency.cs renamed to Analyzer/SQLite/Commands/SerializedFile/AddPreloadDependency.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
namespace UnityDataTools.Analyzer.SQLite.Commands.SerializedFile
66
{
77
/* TABLE DEFINITION:
8-
create table asset_dependencies
8+
create table preload_dependencies
99
(
1010
object INTEGER,
1111
dependency INTEGER,
1212
PRIMARY KEY (object, dependency)
1313
);
1414
*/
15-
internal class AddAssetDependency : AbstractCommand
15+
internal class AddPreloadDependency : AbstractCommand
1616
{
17-
protected override string TableName => "asset_dependencies";
17+
protected override string TableName => "preload_dependencies";
1818

1919
protected override string DDLSource => Resources.AssetBundle;
2020

Analyzer/SQLite/Handlers/AssetBundleHandler.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
namespace UnityDataTools.Analyzer.SQLite.Handlers;
88

99
// Processes the AssetBundle Unity object, which only exists in content built as AssetBundles.
10-
// It fills the assets table from the object's m_Container (the bundle's explicit assets) and adds
11-
// their dependencies from m_PreloadTable. Player and ContentDirectory builds have no AssetBundle
12-
// object, so this handler never runs for them (asset_dependencies can still get rows from other
13-
// sources there - see AssetBundle.sql).
10+
// It fills the assetbundle_assets table from the object's m_Container (the bundle's explicit
11+
// assets) and adds their dependencies from m_PreloadTable. Player and ContentDirectory builds
12+
// have no AssetBundle object, so this handler never runs for them (preload_dependencies can still
13+
// get rows from other sources there - see AssetBundle.sql).
1414
public class AssetBundleHandler : ISQLiteHandler
1515
{
1616
SqliteCommand m_InsertCommand;
@@ -20,8 +20,8 @@ public class AssetBundleHandler : ISQLiteHandler
2020
// This name must match the one SerializedFileSQLiteWriter derives from the scene's file name
2121
// so both compute the same synthetic Scene object id. They only agree for
2222
// BuildPipeline.BuildAssetBundles; for Scriptable Build Pipeline / Addressables and other
23-
// pipelines the writer never creates the Scene object, so the assets row written below points
24-
// at an object id that has no objects-table row (a dangling reference).
23+
// pipelines the writer never creates the Scene object, so the assetbundle_assets row written
24+
// below points at an object id that has no objects-table row (a dangling reference).
2525
private Regex m_SceneNameRegex = new Regex(@"([^//]+)\.unity");
2626

2727
public void Init(SqliteConnection db)
@@ -32,13 +32,13 @@ public void Init(SqliteConnection db)
3232

3333
m_InsertCommand = db.CreateCommand();
3434

35-
m_InsertCommand.CommandText = "INSERT INTO assets(object, name) VALUES(@object, @name)";
35+
m_InsertCommand.CommandText = "INSERT INTO assetbundle_assets(object, name) VALUES(@object, @name)";
3636
m_InsertCommand.Parameters.Add("@object", SqliteType.Integer);
3737
m_InsertCommand.Parameters.Add("@name", SqliteType.Text);
3838

3939
m_InsertDepCommand = db.CreateCommand();
4040

41-
m_InsertDepCommand.CommandText = "INSERT INTO asset_dependencies(object, dependency) VALUES(@object, @dependency)";
41+
m_InsertDepCommand.CommandText = "INSERT INTO preload_dependencies(object, dependency) VALUES(@object, @dependency)";
4242
m_InsertDepCommand.Parameters.Add("@object", SqliteType.Integer);
4343
m_InsertDepCommand.Parameters.Add("@dependency", SqliteType.Integer);
4444
}
@@ -93,10 +93,10 @@ public void Finalize(SqliteConnection db)
9393
{
9494
using var command = new SqliteCommand();
9595
command.Connection = db;
96-
command.CommandText = "CREATE INDEX asset_dependencies_object ON asset_dependencies(object)";
96+
command.CommandText = "CREATE INDEX preload_dependencies_object ON preload_dependencies(object)";
9797
command.ExecuteNonQuery();
9898

99-
command.CommandText = "CREATE INDEX asset_dependencies_dependency ON asset_dependencies(dependency)";
99+
command.CommandText = "CREATE INDEX preload_dependencies_dependency ON preload_dependencies(dependency)";
100100
command.ExecuteNonQuery();
101101
}
102102

Analyzer/SQLite/Handlers/PreloadDataHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
namespace UnityDataTools.Analyzer.SQLite.Handlers;
88

99
// Processes the PreloadData object found in scene bundles. Its m_Assets list is recorded as the
10-
// scene's dependencies (asset_dependencies), so it is meaningful only alongside a synthetic Scene
11-
// object. This is AssetBundle-specific in practice: Player builds also contain a PreloadData
10+
// scene's dependencies (preload_dependencies), so it is meaningful only alongside a synthetic
11+
// Scene object. This is AssetBundle-specific in practice: Player builds also contain a PreloadData
1212
// object but have no scene object, so ctx.SceneId is -1 there and the rows below are written
1313
// against object id -1 (a limitation, not intended output). ContentDirectory builds have neither.
1414
public class PreloadDataHandler : ISQLiteHandler
@@ -19,7 +19,7 @@ public void Init(SqliteConnection db)
1919
{
2020
m_InsertDepCommand = db.CreateCommand();
2121
m_InsertDepCommand.Connection = db;
22-
m_InsertDepCommand.CommandText = "INSERT INTO asset_dependencies(object, dependency) VALUES(@object, @dependency)";
22+
m_InsertDepCommand.CommandText = "INSERT INTO preload_dependencies(object, dependency) VALUES(@object, @dependency)";
2323
m_InsertDepCommand.Parameters.Add("@object", SqliteType.Integer);
2424
m_InsertDepCommand.Parameters.Add("@dependency", SqliteType.Integer);
2525
}

Analyzer/SQLite/Writers/SerializedFileSQLiteWriter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public class SerializedFileSQLiteWriter : IDisposable
4343
// Build Pipeline / Addressables ("CAB-<hash of scene path>") or the Multi-Process Build
4444
// Pipeline ("CAB-<scene GUID>"), nor player-build scenes ("level0", "level1", ...). For
4545
// those builds no synthetic Scene object is created (see the scene handling in
46-
// WriteSerializedFile), so the scene rows AssetBundleHandler writes into assets end up
47-
// dangling and PreloadDataHandler attributes preload dependencies to SceneId -1.
46+
// WriteSerializedFile), so the scene rows AssetBundleHandler writes into assetbundle_assets
47+
// end up dangling and PreloadDataHandler attributes preload dependencies to SceneId -1.
4848
private Regex m_RegexSceneFile = new(@"BuildPlayer-([^\.]+)(?:\.sharedAssets)?");
4949

5050
// Rebuilt for each serialized file: maps a PPtr's local m_FileID (0 = this file, 1..N = an
@@ -75,7 +75,7 @@ public class SerializedFileSQLiteWriter : IDisposable
7575
private AddSerializedFile m_AddSerializedFileCommand = new AddSerializedFile();
7676
private AddObject m_AddObjectCommand = new AddObject();
7777
private AddType m_AddTypeCommand = new AddType();
78-
private AddAssetDependency m_InsertDepCommand = new AddAssetDependency();
78+
private AddPreloadDependency m_InsertDepCommand = new AddPreloadDependency();
7979

8080
private bool m_Initialized;
8181
private SqliteConnection m_Database;
@@ -166,7 +166,7 @@ public void WriteSerializedFile(string relativePath, string fullPath, string con
166166
// A scene has no single Unity object to represent it, yet a scene bundle lists the scene
167167
// (by its .unity path) as the bundle's asset and other objects/preloads need something to
168168
// hang off of. So for scene bundles we synthesize one "Scene" object per scene and use it
169-
// as the target of the assets row (AssetBundleHandler) and of the scene's content and
169+
// as the target of the assetbundle_assets row (AssetBundleHandler) and of the scene's content and
170170
// preload dependencies (below and PreloadDataHandler). This only happens when the file
171171
// name matches m_RegexSceneFile; see its LIMITATION note for the builds this misses (issue 81).
172172
var match = m_RegexSceneFile.Match(relativePath);

Documentation/analyze-examples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ This is a large subject, see [Comparing Builds](comparing-builds.md).
245245

246246
UnityDataTool works on the output of a Unity build, which, by its very nature, only contains the crucial data needed to efficiently load built content in the Player. It does not include complete information about the assets and scenes in the project that was used to create that build. You may want to match content back to the original source asset or scene. For example if the size of an AssetBundle has unexpectedly changed between builds then you may want to track down which source assets could be responsible for that change. Or you may want to confirm that some particular image has been included in the build.
247247

248-
For AssetBundles partial asset information can be found in the m_Containers list, inside the AssetBundle object. This records assets that were explicitly added to AssetBundles. In the database this can be found in the `assets` table. However, assets that are included in the build implicitly (because they are referenced from the explicitly added assets) will not be recorded anywhere in the AssetBundle content.
248+
For AssetBundles partial asset information can be found in the m_Containers list, inside the AssetBundle object. This records assets that were explicitly added to AssetBundles. In the database this can be found in the `assetbundle_assets` table. However, assets that are included in the build implicitly (because they are referenced from the explicitly added assets) will not be recorded anywhere in the AssetBundle content.
249249

250-
Similarly for a player build the only paths populated in the `assets` table are the scenes from the Build Profile Scene List. The paths of the assets in the sharedAsset files is not recorded anywhere in the build output.
250+
For a player build the `assetbundle_assets` table is empty (player builds don’t contain an AssetBundle object), and the paths of assets in the sharedassets files are not recorded anywhere in the build output.
251251

252252
In many cases the source asset can be inferred based on your specific knowledge of your project, and how the build was configured. For example the level files in a Player build match the Scenes in the Build Profile Scene list. And the content of AssetBundles is driven from the assignment of specific assets to those AssetBundles (or Addressable groups), along with assets they depend on.
253253

Documentation/analyzer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ duplicated assets. It also lists all the AssetBundles where the asset was found.
5050
If the `--skip-crc` option is used, there will be a lot of false positives in that view. Otherwise,
5151
it should be very accurate because CRCs are used to determine if objects are identical.
5252

53-
## asset_view (AssetBundleProcessor)
53+
## assetbundle_asset_view (AssetBundleProcessor)
5454

5555
This view lists all the assets that have been explicitly assigned to AssetBundles. The dependencies
5656
that were automatically added by Unity at build time won't appear in this view. The columns are the
5757
same as those in the *object_view* with the addition of the *asset_name* that contains the filename
5858
of the asset.
5959

60-
## asset_dependencies_view (AssetBundleProcessor)
60+
## preload_dependencies_view (AssetBundleProcessor)
6161

6262
This view lists the dependencies of all the assets. You can filter by id or asset_name to get all
6363
the dependencies of an asset. Conversely, filtering by dep_id will return all the assets that

ReferenceFinder/ReferenceFinderTool.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ public ReferenceTreeNode(long id)
1919

2020
public class ReferenceFinderTool
2121
{
22-
// Minimum analyze database schema version find-refs can read. The normalized refs table
23-
// (issue #44) is version 1; databases produced before schema versioning report 0.
24-
const long RequiredSchemaVersion = 1;
22+
// Minimum analyze database schema version find-refs can read. Version 2 renamed the
23+
// assets/asset_view tables this tool queries to assetbundle_assets/assetbundle_asset_view
24+
// (issue #82), so an older database (version 1 or the pre-versioning 0) cannot be read.
25+
const long RequiredSchemaVersion = 2;
2526

2627
SqliteCommand m_GetRefsCommand;
2728
SqliteCommand m_GetObjectCommand;
@@ -137,7 +138,7 @@ int FindReferences(SqliteConnection db, string outputFile, IList<long> objectIds
137138
m_Writer = toStdout ? Console.Out : new StreamWriter(outputFile);
138139

139140
m_GetRefsCommand = db.CreateCommand();
140-
m_GetRefsCommand.CommandText = @"SELECT object, property_path, EXISTS (SELECT * FROM assets a WHERE a.object = r.object) FROM refs_view r WHERE referenced_object = @id";
141+
m_GetRefsCommand.CommandText = @"SELECT object, property_path, EXISTS (SELECT * FROM assetbundle_assets a WHERE a.object = r.object) FROM refs_view r WHERE referenced_object = @id";
141142
m_GetRefsCommand.Parameters.Add("@id", SqliteType.Integer);
142143

143144
// Resolve the 'm_Script' property path to its id once so the per-object script lookup below
@@ -190,7 +191,7 @@ FROM object_view o
190191

191192
ProcessReferences(objectIds[i], findAll);
192193

193-
command.CommandText = "SELECT asset_name, asset_bundle, serialized_file FROM asset_view WHERE id = @id";
194+
command.CommandText = "SELECT asset_name, asset_bundle, serialized_file FROM assetbundle_asset_view WHERE id = @id";
194195

195196
foreach (var root in m_Roots)
196197
{

UnityDataTool.Tests/ExpectedDataGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static void Generate(Context context)
3838
@"SELECT
3939
(SELECT COUNT(*) FROM animation_clips),
4040
(SELECT COUNT(*) FROM asset_bundles),
41-
(SELECT COUNT(*) FROM assets),
41+
(SELECT COUNT(*) FROM assetbundle_assets),
4242
(SELECT COUNT(*) FROM audio_clips),
4343
(SELECT COUNT(*) FROM meshes),
4444
(SELECT COUNT(*) FROM monoscripts),

0 commit comments

Comments
 (0)