Help:Temporary tables

From semantic-mediawiki.org
Jump to: navigation, search

Temporary tables are used to hold temporary computed results during a query execution and while kept in memory those will be deleted after a query execution has finished.

Example

Below shows an example for when temporary tables (marked with t.) are created and used by a query.

{{#ask: 
 [[Category:City]] OR  [[Located in::Germany]] 
 |format=debug
}}
SQLStore debug output
ASK Query
[[Category:City]] OR [[Located in::Germany]]
SQL Query
SELECT DISTINCT
  t0.smw_id AS id,
  t0.smw_title AS t,
  t0.smw_namespace AS ns,
  t0.smw_iw AS iw,
  t0.smw_subobject AS so,
  t0.smw_sortkey AS sortkey, t0.smw_sortkey
FROM
  `smw_object_ids` AS t0
INNER JOIN
  `t1` AS t1 ON t0.smw_id=t1.id
WHERE
  t0.smw_iw!=':smw'
  AND t0.smw_iw!=':smw-delete'
  AND t0.smw_iw!=':smw-redi'
ORDER BY
  t0.smw_sortkey ASC
LIMIT
  55
OFFSET
  0
SQL Explain
IDselect_typetabletypepossible_keyskeykey_lenrefrowsExtra
1SIMPLEt1ALLPRIMARY43Using temporary; Using filesort
1SIMPLEt0eq_refPRIMARY,smw_id,smw_iwPRIMARY4DB0231020151216.t1.id1Using where
Auxilliary Tables
  • Temporary table t1
      INSERT IGNORE INTO `t1` SELECT DISTINCT t2.s_id FROM `smw_fpt_inst` AS t2 INNER JOIN `t3` AS t3 ON t2.o_id=t3.id
      INSERT IGNORE INTO `t1` SELECT DISTINCT t4.s_id FROM `smw_di_wikipage` AS t4 INNER JOIN `t5` AS t5 ON t4.p_id=t5.id WHERE t4.o_id='779'
  • Temporary table t3
      Recursively computed hierarchy for element(s) ('490').
  • Temporary table t5
      Recursively computed hierarchy for element(s) ('86').
Query Metrics
Query-Size:3
Query-Depth:1
Errors and Warnings
None

Disable temporary tables

You can disable specific query features that rely on temporary tables (necessary when computing intermediary results) by adding the following to "LocalSettings.php":

$smwgQSubcategoryDepth = 0;
$smwgQSubpropertyDepth = 0;
$smwgQFeatures         = SMW_ANY_QUERY & ~SMW_DISJUNCTION_QUERY;
$smwgQConceptFeatures  = SMW_ANY_QUERY & ~SMW_DISJUNCTION_QUERY & ~SMW_CONCEPT_QUERY;


See also