# How does drvid in sqlth\_partitions relate to scid and to entries in sqlth\_te?

**URL:** <https://forum.inductiveautomation.com/t/how-does-drvid-in-sqlth-partitions-relate-to-scid-and-to-entries-in-sqlth-te/23840>\
**Category:** Ignition\
**Created:** [April 4, 2019, 12:19am UTC](https://forum.inductiveautomation.com/t/how-does-drvid-in-sqlth-partitions-relate-to-scid-and-to-entries-in-sqlth-te/23840 "2019-04-04T00:19:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpderbec](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@mpderbec](https://forum.inductiveautomation.com/u/mpderbec)\
**Post date:** [April 4, 2019, 12:19am UTC](https://forum.inductiveautomation.com/t/how-does-drvid-in-sqlth-partitions-relate-to-scid-and-to-entries-in-sqlth-te/23840/1 "2019-04-04T00:19:36Z")

</div>

I’m trying to figure out if my SQL queries should care about the drvid that is in the sqlth\_partitions table. I need to go from an entry in sqlth\_te to a query against a historical data table (e.g., sqlt\_data\_1\_2019\_04).

Here’s a snapshot of the tables on a clean installation of Ignition:  
 ![Capture](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/4fe5e86d1d4314f298723d8acf4e15b4d51d8d09.png)

![Capture2](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/a57903be602052419fddc784f2dc0bd80e4f9831.png)

![Capture3](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/4bb006fb099e6f21155c2dfda7653117b0252c5c.png)

All good so far… we can map from a tag entry to a drvid.

Now we look in sqlth\_partitions:

![Capture4](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/ebd32986e49e31500e071b4bc7b2f3b60dca3e13.png)

No entry for drvid == 2.

How do I make that final leap?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 4, 2019, 3:09pm UTC](https://forum.inductiveautomation.com/t/how-does-drvid-in-sqlth-partitions-relate-to-scid-and-to-entries-in-sqlth-te/23840/2 "2019-04-04T15:09:11Z")

</div>

If you will only ever have one Ignition gateway talking to this database, then you can _probably_ ignore `sqlth_drv` - you will still need it if you add any more realtime tag providers to this gateway as well.

---

<div class="post-metadata">

**Author:** ![mpderbec](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@mpderbec](https://forum.inductiveautomation.com/u/mpderbec)\
**Post date:** [April 4, 2019, 3:12pm UTC](https://forum.inductiveautomation.com/t/how-does-drvid-in-sqlth-partitions-relate-to-scid-and-to-entries-in-sqlth-te/23840/3 "2019-04-04T15:12:23Z")

</div>

Thanks PGriffith-- however it is the case that there will be multiple gateways/providers. (This question is in the context of an Ignition Module that my company writes and maintains.)

One pattern I noticed is that the sqlth\_partitions table only ever seems to reference a drvid entry in sqlth\_drv where “provider” is null. Is that always the case? If so I could do this (somewhat crazy) SQL command to narrow in on the drvid that is used by sqlth\_partitions:

```auto
SELECT sqlth_te.id AS tagid, gateway.id as drvid FROM sqlth_te
  INNER JOIN sqlth_scinfo ON sqlth_scinfo.id = sqlth_te.scid
  INNER JOIN sqlth_drv ON sqlth_drv.id = sqlth_scinfo.drvid
  INNER JOIN sqlth_drv AS gateway ON sqlth_drv.name = gateway.name
  WHERE gateway.provider IS NULL;

```

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [December 21, 2022, 9:12pm UTC](https://forum.inductiveautomation.com/t/how-does-drvid-in-sqlth-partitions-relate-to-scid-and-to-entries-in-sqlth-te/23840/4 "2022-12-21T21:12:01Z")

</div>

I know this conversation is old, but it was never really resolved and I'm curious about the same thing.

I just setup a brand new Ignition (8.1.22) and DB to do some development work and right out of the gate noticed that the `drvid` is mismatched. All of the tags in sqlth\_te are referencing the only scinfo entry, which has a drvid=2 ... but all the partition entries say drvid=1 and those are indeed the tables that the history is landing in...

```auto
MariaDB [ignitiondb]> SELECT DISTINCT(scid) FROM sqlth_te;
+------+
| scid |
+------+
| 1 |
+------+
1 row in set (0.001 sec)

MariaDB [ignitiondb]> SELECT * FROM sqlth_scinfo;
+----+----------+-------+
| id | scname | drvid |
+----+----------+-------+
| 1 | _exempt_ | 2 |
+----+----------+-------+
1 row in set (0.001 sec)

MariaDB [ignitiondb]> SELECT * FROM sqlth_partitions;
+---------------------+-------+---------------+---------------+-----------+-------+
| pname | drvid | start_time | end_time | blocksize | flags |
+---------------------+-------+---------------+---------------+-----------+-------+
| sqlt_data_1_2022_12 | 1 | 1669852800000 | 1672531200000 | 0 | NULL |
+---------------------+-------+---------------+---------------+-----------+-------+
1 row in set (0.001 sec)

```

I can't ignore this since our production DB has accumulated history from multiple gateways and I need to be sure I'm looking at the right tables. Why is it _already_ apparently mismatched on the very first entries being made?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 21, 2022, 9:33pm UTC](https://forum.inductiveautomation.com/t/how-does-drvid-in-sqlth-partitions-relate-to-scid-and-to-entries-in-sqlth-te/23840/5 "2022-12-21T21:33:31Z")

</div>

It's not represented as a(n) SQL relationship, but there are always at least two records in `sqlth_drv`:

> [@Can I have two gateways using the same SQL database for historic logging?](https://forum.inductiveautomation.com/t/can-i-have-two-gateways-using-the-same-sql-database-for-historic-logging/56816/2):
>
> Not a problem at all (as long as they have distinct gateway names). The historian already uniquely identifies every record by what system and tag provider it came from. Check sqlth\_drv, there will be at least two records (one null, one probably with an entry for default) for each gateway you connect to a given historian.

Each tag provider you add to a given gateway will create a new row in `sqlth_drv` with the gateway name and provider name. When it comes time to retrieve history, the historian "knows" to look for the entry with a null provider.

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [December 21, 2022, 9:38pm UTC](https://forum.inductiveautomation.com/t/how-does-drvid-in-sqlth-partitions-relate-to-scid-and-to-entries-in-sqlth-te/23840/6 "2022-12-21T21:38:31Z")

</div>

So, in general, a sqlth\_te will reference to a sqlth\_drv entry with both a gateway and provider name. But when looking up data entries for that tag, I can look for partitions using either that specific drv ID _or_ the one that has the same gateway name and a NULL provider?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 21, 2022, 9:44pm UTC](https://forum.inductiveautomation.com/t/how-does-drvid-in-sqlth-partitions-relate-to-scid-and-to-entries-in-sqlth-te/23840/7 "2022-12-21T21:44:11Z")

</div>

It depends on what you're trying to do, exactly.  
The `scid` corresponding to a specific `id` in `sqlth_te` will be 1:1 with an `id` in `sqlth_scinfo`.  
The `drvid` corresponding to a specific `id` in `sqlth_scinfo` will be 1:1 with an `id` in `sqlth_drv`.

So given _just_ a path, you need to go from `sqlth_te` -\> `sqlth_scinfo` -\> `sqlth_drv`, and then from _there_ find the entry with the matching gateway name but a null provider ID. That ID will be the prefix used for historical tables.
