# Check all named graphs

**URL:** <https://community.stardog.com/t/check-all-named-graphs/2871>\
**Category:** Support\
**Created:** [January 19, 2021, 8:08pm UTC](https://community.stardog.com/t/check-all-named-graphs/2871 "2021-01-19T20:08:02Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![arwesterinen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/arwesterinen/32/40_2.png) [@arwesterinen](https://community.stardog.com/u/arwesterinen)\
**Post date:** [January 19, 2021, 8:08pm UTC](https://community.stardog.com/t/check-all-named-graphs/2871/1 "2021-01-19T20:08:02Z")

</div>

Is there a quick way to check for all named graphs in a db?

We are running a "select distinct ?g where {graph ?g {?s \<specific\_low\_use\_predicate\> ?o}}" but performance is still over a minute. (We have about 150 named graphs.)

Any suggestions would be appreciated.

Andrea

---

<div class="post-metadata">

**Author:** ![pavel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pavel/32/18_2.png) [@pavel](https://community.stardog.com/u/pavel)\
**Post date:** [January 19, 2021, 8:22pm UTC](https://community.stardog.com/t/check-all-named-graphs/2871/2 "2021-01-19T20:22:36Z")

</div>

Hi Andrea,

```auto
select ?g { graph ?g {} }

```

should work with a recent version of Stardog.

Best,  
Pavel

---

<div class="post-metadata">

**Author:** ![rameshm76](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/rameshm76/32/991_2.png) [@rameshm76](https://community.stardog.com/u/rameshm76)\
**Post date:** [January 19, 2021, 8:22pm UTC](https://community.stardog.com/t/check-all-named-graphs/2871/3 "2021-01-19T20:22:53Z")

</div>

HTH

select distinct ?g  
where {  
graph ?g {}  
}

---

<div class="post-metadata">

**Author:** ![arwesterinen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/arwesterinen/32/40_2.png) [@arwesterinen](https://community.stardog.com/u/arwesterinen)\
**Post date:** [January 19, 2021, 10:09pm UTC](https://community.stardog.com/t/check-all-named-graphs/2871/4 "2021-01-19T22:09:33Z")

</div>

Pavel, I did try that as well. It was a BIT faster at 56 secs (not greater than 1 min) but still that is kind of bad (IMHO).

Andrea

---

<div class="post-metadata">

**Author:** ![pavel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pavel/32/18_2.png) [@pavel](https://community.stardog.com/u/pavel)\
**Post date:** [January 19, 2021, 10:14pm UTC](https://community.stardog.com/t/check-all-named-graphs/2871/5 "2021-01-19T22:14:30Z")

</div>

It is bad indeed and strongly suggests `db optimize` is needed (unless your named graphs aren't added/deleted, in which case we need to investigate what's going on).

Best,  
Pavel

---

<div class="post-metadata">

**Author:** ![arwesterinen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/arwesterinen/32/40_2.png) [@arwesterinen](https://community.stardog.com/u/arwesterinen)\
**Post date:** [January 19, 2021, 10:18pm UTC](https://community.stardog.com/t/check-all-named-graphs/2871/6 "2021-01-19T22:18:05Z")

</div>

Now that you say that ... we are testing some new software and named graphs come and go.

Might the lack of optimization also account for high memory usage?

Can optimize run while the db is in use or does it have to quiesced?

Andrea

---

<div class="post-metadata">

**Author:** ![pavel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pavel/32/18_2.png) [@pavel](https://community.stardog.com/u/pavel)\
**Post date:** [January 19, 2021, 10:43pm UTC](https://community.stardog.com/t/check-all-named-graphs/2871/7 "2021-01-19T22:43:48Z")

</div>

It's possible. Lots of data writes without `db optimize` likely means the data is scattered over a large number of files. Reading those files during query evaluation will consume more memory than if the data layout was optimal.

But the biggest factor here is that reads get slower as they have to i) read more files, ii) skip over deleted data.

Yes, `db optimize` runs transparently to concurrent operations.

Best,  
Pavel

---

<div class="post-metadata">

**Author:** ![arwesterinen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/arwesterinen/32/40_2.png) [@arwesterinen](https://community.stardog.com/u/arwesterinen)\
**Post date:** [January 19, 2021, 11:22pm UTC](https://community.stardog.com/t/check-all-named-graphs/2871/8 "2021-01-19T23:22:52Z")

</div>

I will try that and report back.

Thank you so much for the insights.

Andrea

---

<div class="post-metadata">

**Author:** ![arwesterinen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/arwesterinen/32/40_2.png) [@arwesterinen](https://community.stardog.com/u/arwesterinen)\
**Post date:** [January 20, 2021, 12:13am UTC](https://community.stardog.com/t/check-all-named-graphs/2871/9 "2021-01-20T00:13:55Z")

</div>

Yup, I am an idiot. Your suggestion helped a lot for performance of the distinct ?g query.

However, my server memory is still being consumed at a dangerous rate.

Any other suggestions will be tested immediately :-).

Andrea

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [February 3, 2021, 12:13am UTC](https://community.stardog.com/t/check-all-named-graphs/2871/10 "2021-02-03T00:13:59Z")

</div>

Closed on February 3, 2021, 12:13am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
