# Queries

**Queries** are not only a way to optimise, but a fundamental tool for Clients to specify what part(s) of the online world they are interested in.

With them, the Replication Server can filter the information to send based on each Client's interest, and thus greatly optimise network traffic.

<figure><img src="https://content.gitbook.com/content/CMCtKgV0bk1lwR4tWK3W/blobs/OGf3IZpQ0nKT8pUL3d1u/LiveQueries.jpg" alt=""><figcaption><p>In the left window, Player2 is not visible because it's outside of Player1's LiveQueries</p></figcaption></figure>

At the moment, coherence offers three ways to filter network entities: [**Live Query**](https://docs.coherence.io/manual/components/coherence-live-query)**,** [**Tag Query**](https://docs.coherence.io/manual/components/coherence-tag-query) **and** [**Global Query**](https://docs.coherence.io/manual/components/coherenceglobalquery).

* With [**Live Queries**](https://docs.coherence.io/manual/components/coherence-live-query) the filtering is volume-based, kind of like moving a torch to look around in a dark cave.
* With [**Tag Queries**](https://docs.coherence.io/manual/components/coherence-tag-query) even distant entities can be seen, provided they have the right [Tag](https://docs.coherence.io/components/coherence-sync#tag).
* With [**Global Queries**](https://docs.coherence.io/manual/components/coherenceglobalquery) any entities marked as [Is Global](https://docs.coherence.io/components/coherence-sync#is-global) can be seen.

{% hint style="warning" %}
You **need at least one** query in your scene, or you won't see anything update over the network. All queries are combined and a union of all matching entities are made visible to the client.
{% endhint %}

When a non-authoritative entity **falls outside** of all queries, it gets **destroyed** (or returned to an object pool). When it gets back in, it gets re-instantiated (or taken out of the pool). If the right properties are synced, the entity's state will be automatically restored by coherence, making the player feel like that entity never disappeared.

{% hint style="info" %}
Queries only filter network entities that are **non-authoritative**. Your own entities will never be destroyed for falling outside of a query.
{% endhint %}

## Queries are additive

When using queries and adding more than one, they act in an **additive** way.

So for instance, two overlapping **LiveQueries** will define a bigger area.

Similarly, a **LiveQuery** + a **TagQuery** will add up, looking for entities both within a range but also for the ones that have a certain tag, regardless of position.

{% hint style="info" %}
Non-additive filtering will come in a future version of coherence.
{% endhint %}

## Runtime changes

It is a very common pattern to **move** a LiveQuery around, following a player character or the camera, to ensure the visible entities are updated.

In addition to this, queries can be **turned on/off** (simply by disabling them), or **their properties can be changed** at runtime (like radius, position, or tag), making for a very dynamic tool to optimise bandwidth.

## Queries are personal

Queries are per-Client, meaning that each Client (or Simulator!) has its own queries and thus sees different parts of the simulation.

{% hint style="success" %}
Queries can also be used for cheat prevention, see [Server authoritative setup](https://docs.coherence.io/manual/authority/server-authoritative-setup) for more information.
{% endhint %}
