SMW database error
> We are using the older 1.8.0.5 version of SMW with MediaWiki 1.20.2, PHP 5.4.9, MySQL 5.5.28.
Honestly it will be difficult for use to make any suggestions since you are using a no longer maintained code base (SMW 1.8*). It will be toilsome for us to make an appropriate response but we are tracking the issue at [0].
> It seems to occur only a specific type of page invoking a specific template.
Is it possible for you to post the details of your analysis to [0]?
Also, could you try running an isolated stack trace to see whether the queries are caught in a resource loop and link the report to [0]. Limit your pages when running the job because "$wgDebugDumpSql = true" is expensive as it returns each single SQL query executed.
[0] https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/918