Can you describe the size of your wiki and amount of redirects? 34 minutes seems to be a huge number.
Can you also give an example of SMW query that ran that long?


On Nov 18, 2007 7:05 PM, Audra Johnson <> wrote:
A few weeks ago, I discovered that searches with a few subqueries
were dreadfully slow and found the cause to be making annotated
redirects equivalent to their targets.  I suggested making redirect
equivalency a SMW option--but when I went scanning for how to
implement it, I gleefully found that it was already included!  The
setting is:

$smwgQEqualitySupport = true; // Should #redirects be evaluated as
equality between page names?

(It should probably include a note about efficiency for its comment,
just like the one for $smwgQDefaultNamespaces--taking out redirect
equality support can make a HUGE difference for more complex
queries.  HUGE being the difference between a three subquery search
taking 34 minutes with redirect equivalency and .3 seconds without.)

In any case, my semantic wiki has been happily humming and searching
along since I set $smwgQEqualitySupport to false.    But I also need
a way to tell where annotations in the wiki are pointing to
redirected pages, so they can be fixed.

So I've made a special page for redirected annotations that extends
SMWQueryPage.  This will make it easy for people to find where
annotations are pointing to redirected pages and fix them to point at
the right ones.

Messages that would are added for this page:

       // Messages for Redirected Annotations Special
       'redirectedannotations' => 'Redirected annotations',
       'smw_redirectedannotations_docu' => 'The object of these annotations
points to a redirected page.',
       'smw_redirectedannotations_template' => 'On page $1, the annotation
$2::$3 redirects to $4.',

It required one additional function to SMW_SQLStore in the "Special
page functions" section:

function getRedirectedAnnotationsSpecial($requestoptions = NULL) {
               wfProfileIn("SMWSQLStore::getRedirectedAnnotationsSpecial (SMW)");
               $db =& wfGetDB( DB_SLAVE );
               $options = ' ORDER BY subject_title';

               if ($requestoptions->limit > 0) {
                       $options .= ' LIMIT ' . $requestoptions->limit;
               if ($requestoptions->offset > 0) {
                       $options .= ' OFFSET ' . $requestoptions->offset;

               extract( $db->tableNames('smw_relations', 'redirect') );

               $res = $db->query("SELECT subject_title, subject_namespace,
relation_title, object_title, object_namespace, rd_title,
rd_namespace FROM $smw_relations "
                       . "INNER JOIN $redirect ON $smw_relations.object_id =
                       . $options, 'SMW::getRedirectedAnnotationsSpecial');
               $result = array();

               while($row = $db->fetchObject($res)) {
                       $subject_page = Title::newFromText($row->subject_title, $row-
                       $relation_page = Title::newFromText($row->relation_title,
                       $object_page = Title::newFromText($row->object_title, $row-
                       $rd_page = Title::newFromText($row->rd_title, $row->rd_namespace);
                       $result[] = array($subject_page, $relation_page, $object_page,

               wfProfileOut("SMWSQLStore::getRedirectedAnnotationsSpecial (SMW)");
               return $result;

And it needs to be added in the enableSemantics() function in

$wgSpecialPages['RedirectedAnnotations']       = array
'smwfDoSpecialRedirectedAnnotations', $smwgIP . '/specials/QueryPages/

I've attached the PHP code for the page itself.

Am looking for input on:

* Whether the special page should be initialized and included only if
$smwgQEqualitySupport = false
* Whether the page name RedirectedAnnotations is an adequate name
* Other wording that should be changed or tweaked.  For example, in
the smw_redirctedannotations_temp:
* Message text:  "the annotation Similar to::X redirects to Y." or
"the relation Similar to::X redirects to Y.", since this only happens
to relation annotations? "The object of these annotations points to a
redirected page." or "The object of these relations points to a
redirected page." ?
* Coding style

This email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
Semediawiki-devel mailing list

Sergey Chernyshev