Page MenuHomePhabricator

rev_comment_id, comment_id join clause
Closed, ResolvedPublic

Description

The following query yields ERROR 1054 (42S22): Unknown column 'rev_comment_id' in 'on clause'.

SELECT rev_timestamp, actor_name, page_title, rev_parent_id
FROM revision
   JOIN comment ON rev_comment_id = comment_id
   JOIN actor ON rev_actor = actor_id
   JOIN page ON rev_page = page_id
 WHERE (EXISTS (SELECT * FROM change_tag WHERE ct_rev_id = rev_id AND ct_tag_id = 22) /* ="Android app edit" */
    OR comment_text LIKE "%Via Commons Mobile App%"
    OR comment_text LIKE "%using Android Commons%"
    OR comment_text LIKE "%COM:MOA%")
 AND rev_timestamp >= "20200201" AND rev_timestamp < "20200209"
ORDER BY rev_timestamp DESC

Is there a way to adapt the query so that it will work with the updated schemas and achieve the same result as before? This task's author looked around at some of the table definitions in MariaDB, MediaWiki.org documentation, and Phabricator but wasn't completely sure of the best way.

Event Timeline

There's no rev_comment_id in MW core (yet).. But there is revcomment_comment_id in the revision_comment_temp table...

For now... Match revcomment_rev = rev_id, and then revcomment_comment_id = comment_id

-- Text comment summarizing the change. Deprecated in favor of
-- revision_comment_temp.revcomment_comment_id.
rev_comment varbinary(767) NOT NULL default '',
--
-- Temporary table to avoid blocking on an alter of revision.
--
-- On large wikis like the English Wikipedia, altering the revision table is a
-- months-long process. This table is being created to avoid such an alter, and
-- will be merged back into revision in the future.
--
CREATE TABLE /*_*/revision_comment_temp (
  -- Key to rev_id
  revcomment_rev int unsigned NOT NULL,
  -- Key to comment_id
  revcomment_comment_id bigint unsigned NOT NULL,
  PRIMARY KEY (revcomment_rev, revcomment_comment_id)
) /*$wgDBTableOptions*/;
-- Ensure uniqueness
CREATE UNIQUE INDEX /*i*/revcomment_rev ON /*_*/revision_comment_temp (revcomment_rev);

Looks like the docs were added in https://www.mediawiki.org/w/index.php?title=Manual%3ARevision_table&type=revision&diff=2960095&oldid=2958720 possibly expecting a patch to land?

Anomie assigned this task to Reedy.
Anomie subscribed.

Closing as the task is asking "how to fix this query", which was answered by @Reedy in T244786#5866961. Note the same applies to rev_actor, the column is currently in revision_actor_temp as revactor_actor.

In` as T244786#5866961, @Reedy wrote:

Possibly someone was confused by the fact that Toolforge's replica views simulate rev_comment_id, which was done so tools wouldn't have to change to use revision_comment_temp and then change to rev_comment_id shortly after.