What's the point of passing queries to IJobEntity?

There’s an option to pass an already created EntityQuery to an IJobEntity on the Schedule(query, handle) method.

But then you have to define the same components on the query in the Execute Method. And it can cointain more components…

Not passing the query would generate the query anyway.
And if it has more components, it would generate a new query, does it?

What’s the point of doing this? How are Queries reused? It works faster? Creates a copied query defined on the System?

Thanks

If you only ever use the job with a passed-in query, it won’t generate the job’s default query.

One of the common use cases for this is to work around bugs with automatic query generation specifically when IEnableableComponent is involved.

A less common use case is when you want to use the same job on slightly different queries, such as with shared component filtering.

In my case I don’t depend on the auto-generated queries but spell them out explicitly via SystemAPI.QueryBuilder()

Thanks.
I don’t completely get it.

So

Query (A, B)
Job.Schedule(query)
Job Execute ( A, B, C )

The query built for the system and cached is A,B,C AND A,B? I guess it’s bad because I’m just going to use ABC?

The implicit query is only set up if there’s a usage of an IJobEntity that does not pass a query parameter. If an IJobEntity type is only scheduled with an explicit passed query, the default query for that job won’t be allocated.

// default query created at system creation
jobEntity.Schedule();

// default query not created, passed query used
jobEntity.Schedule(query);

You need to individually make sure that your own queries contain all the component types retrieved from the chunk. You’ll get an error if you try to pass a query missing some of the necessary components.

SystemState.GetEntityQuery returns the same EntityQuery for different exactly matching queries within that system.

EntityManager.CreateEntityQuery creates an allocation for a new EntityQuery (this allows for adding filters on top of the component rules) but reuses existing underlying query data for an exactly matching query if it exists, or builds the full query data otherwise.

There is a typo in your example: you forgot to pass the query to the second schedule.