I was using stardog studio to execute the queries directly, from my experience the pragma is preserved here.
The data queried here differs in two ways from BSBM: we have many more (and sparse) properties to (400+) and many graphs (600+) , with only a few containing the data.
While compiling the information about the query plan i found discovered hopefully the root cause, all exeuted on stardog 6:
with no from clause given, the query as the following plan and executed in ~4 sec
From all
Distinct [#1.4K]
`β Projection(?predicate) [#14.0M]
`β BindJoin(?predicate) [#14.0M]
+β Distinct [#1.4K]
β `β Projection(?predicate) [#11K]
β `β Scan[PC](_, ?predicate, _) [#11K]
`β MergeJoin(?instance) [#16.7M]
+β Distinct [#2.3M]
β `β Scan[POSC](?instance, <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, :myClass) [#2.6M]
`β Scan[SPOC](?instance, ?predicate, ?any) [#126.9M]
With a single from clause, the query has the follwing plan and executes in ~10sec
From <mygraph1>
Distinct [#1.4K]
`β Projection(?predicate) [#12.0M]
`β HashJoin(?instance) [#12.0M]
+β MergeJoin(?predicate) [#12.0M]
β +β Distinct [#1.4K]
β β `β Projection(?predicate) [#2.5K]
β β `β Scan[PC](_, ?predicate, _) [#2.5K]
β `β Scan[PSC](?instance, ?predicate, _) [#21.0M]
`β Distinct [#501K]
`β Scan[POSC](?instance, <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, :myClass) [#501K]
with ~200 named graphs the query produces the following query plan and executes in ~30 seconds
with pragma:
From <mygraph2>
From <mygraph3>
From <mygraph4>
Distinct [#1.4K]
`β Projection(?predicate) [#12.0M]
`β HashJoin(?instance) [#12.0M]
+β MergeJoin(?predicate) [#12.0M]
β +β Distinct [#1.4K]
β β `β Projection(?predicate) [#2.7K]
β β `β Scan[PC](_, ?predicate, _) [#2.7K]
β `β Scan[PSC](?instance, ?predicate, _) [#22.7M]
`β Distinct [#501K]
`β Scan[POSC](?instance, <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, :myClass) [#501K]
For the sake of completeness, here is the query plans w/o the pragma
Distinct [#1.4K]
`β Projection(?predicate) [#12.0M]
`β HashJoin(?instance) [#12.0M]
+β MergeJoin(?predicate) [#12.0M]
β +β Distinct [#1.4K]
β β `β Projection(?predicate) [#2.7K]
β β `β Scan[PC](_, ?predicate, _) [#2.7K]
β `β Scan[PSC](?instance, ?predicate, _) [#22.7M]
`β Distinct [#501K]
`β Scan[POSC](?instance, <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, :myClass) [#501K]