System details: Apache 2.2, Tomcat 6.0.20, Solr 1.4.0 (final), Windows Server 2003 SP2

Indexing stopped working on my site yesterday (more details on this below). New nodes are not added, but existing search works. When I attempt to re-index the site to see if that will fix the issue, I get the following error:

user warning: Column 'changed' cannot be null query: INSERT INTO apachesolr_search_node (nid, status, changed) SELECT n.nid, n.status, GREATEST(n.created, n.changed, c.last_comment_timestamp) AS changed FROM node n LEFT JOIN node_comment_statistics c ON n.nid = c.nid in
\htdocs\sites\all\modules\apachesolr\apachesolr.module on line 281.

I upgraded to 6.x-1.0-rc3 and Apache Solr 1.4.0 final release to see if that would fix the issue. The most frustrating thing is that I copied my entire Drupal site and Solr data to an xampp instance, and the problem vanishes.

The MySQL apachesolr_search_node table is emptied as the first query in the apachesolr.module apachesolr_rebuild_index_table function commands, but the insert fails.

But this may just be a symptom of a larger issue, as I indicated that I started all of this when new nodes ceased indexing.

Comments

dogbertdp’s picture

Correction: Indexing of new nodes is working, it's just that some recent nodes are missing. I'm still unable to re-index the site without the same error occurring.

dogbertdp’s picture

Title: "Column 'changed' cannot be null query" watchdog error when attempting Re-index all content because indexing stopped working » "Column 'changed' cannot be null query" watchdog error when attempting 'Re-index all content' when using MySQL InnoDB

If I run the query below on my production MySQL database, which is using InnoDB, I get the error "#1048 - Column 'changed' cannot be null". The same query on my test MySQL database, which is using MyISAM apparently returns an 'empty set'. When I change my test database to Innodb, I get the same error. These are the lines along which I am troubleshooting this issue.

Here is the query:

INSERT INTO `apachesolr_search_node` (nid, status, changed)
SELECT n.nid, n.status, GREATEST(n.created, n.changed, c.last_comment_timestamp) AS changed
FROM `node` n
LEFT JOIN `node_comment_statistics` c ON n.nid = c.nid

This has been an issuing in MySQL in years past, but everything I'm finding suggests that all reported bugs related to this condition are resolved. I'm running MySQL 5.1.37, which is only a few months old as of this writing.

Here are the contents of my my.ini (sans comments with the disk paths sanitized):
[client]
port=3306

[mysql]
default-character-set=latin1

[mysqld]
port=3306
bind-address=127.0.0.1
basedir="[path-snip]/mysql/"
datadir="[path-snip]/mysql/Data/"
default-character-set=latin1
default-storage-engine=INNODB
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
max_connections=150
max_user_connections = 150
max_connect_errors = 1000
query_cache_size=16M
table_cache=1024
interactive_timeout = 25
wait_timeout = 1800
tmp_table_size=39M
thread_cache_size=286
join_buffer_size = 2M
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=77M
key_buffer_size=63M
read_buffer_size=64K
read_rnd_buffer_size=256K
sort_buffer_size=3M
innodb_additional_mem_pool_size=2551K
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=1250K
innodb_buffer_pool_size=121M
innodb_log_file_size=61M
innodb_thread_concurrency=8
set-variable = lower_case_table_names=0

Note that I updated the title to reflect my findings.

Any ideas?

Mike Hays

dogbertdp’s picture

Category: support » bug

Ok, so I'm grokking what is going on here. The bug is deeper than I thought. It has little to do with InnoDB, it just turns out that InnoDB doesn't deal with what is going on as "well" as MyISAM.

The following query:

INSERT INTO `apachesolr_search_node` (nid, status, changed)
SELECT n.nid, n.status, GREATEST(n.created, n.changed, c.last_comment_timestamp) AS changed
FROM `node` n
LEFT JOIN `node_comment_statistics` c ON n.nid = c.nid

Always returns NULL for changed on my site, as I don't have comments enabled. So a query for last_comment_timestamp in node_comment_statistics will always return NULL, and as of MySQL 5.0.13 GREATEST will return NULL if anything it evaluates against IS NULL (c.f., http://bugs.mysql.com/bug.php?id=15610).

Since comments aren't required for Drupal, we need to handle this in the re-index code.

Here is my suggestion:

INSERT INTO `apachesolr_search_node` (nid, status, changed)
SELECT n.nid, n.status, GREATEST(n.created, n.changed, IFNULL(c.last_comment_timestamp,0)) AS changed
FROM `node` n
LEFT JOIN `node_comment_statistics` c ON n.nid = c.nid

In the above case, if node_comment_statistics changed is NULL, it will be set to zero, which will always evaluate as less than node created or changed.

Thoughts?

dogbertdp’s picture

StatusFileSize
new725 bytes

The attached patch makes the changes proposed in #3.

pwolanin’s picture

somehow I thought there was already a patch in the queue to fix this bug, but I'm not seeing it immediately. At the least, it's ringing a bell as something reported before.

An alternative is to issue a different query if comment module is not enabled?

Scott Reynolds’s picture

Status: Active » Needs work

An alternative is to issue a different query if comment module is not enabled?

I would advocate this. Complex queries tend to be fragile and this patch is complex needlessly. We should do a

  if (module_exists('comment')) {
  }
  else {
  }
Scott Reynolds’s picture

Version: 6.x-1.0-rc3 » 6.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.43 KB

Attach is a patch against 2.x. Relatively untested so please do review.

pwolanin’s picture

looks reasonable - comment module populates this column when it's enabled, right?

robertdouglass’s picture

in a later incarnation we can test on entity type.

dogbertdp’s picture

Very good. I reverted my changes from #4, applied the patch in #7, and my test site re-indexes as expected. I then enabled the Comment module, confirmed that the 'node_comment_statistics' table last_comment_timestamp column is now populated (it is), and re-indexed the site with no errors.

Looks like a winner to me.

pwolanin’s picture

patch applies with offset to 6.x-1.x. I think this is safe to commit.

pwolanin’s picture

StatusFileSize
new2.22 KB

comitted this to 6.x-1.x

robertdouglass’s picture

Version: 6.x-2.x-dev » 5.x-2.x-dev
Status: Needs review » Patch (to be ported)

Committed to 6.2.

spjsche’s picture

Subscribing....

spjsche’s picture

I am running Drupal v6.15 and have installed the latest version of Apache Solr 6.x-2.x-dev. I have the comments module disabled and cannot get anything to index, keep getting the user warning below even though there are nodes to index.
Is this the same issue as mentioned above ?

# user warning: Column 'changed' cannot be null query: INSERT INTO apachesolr_search_node (nid, status, changed) SELECT n.nid, n.status, GREATEST(n.created, n.changed, c.last_comment_timestamp) AS changed FROM node n LEFT JOIN node_comment_statistics c ON n.nid = c.nid in ..................\sites\all\modules\apachesolr\apachesolr.module on line 277.
# 0 items successfully processed.

Thanks
Stephen

robertdouglass’s picture

Version: 5.x-2.x-dev » 6.x-2.x-dev
Status: Patch (to be ported) » Needs work

@spjsche will take a look.

claudiu.cristea’s picture

StatusFileSize
new2.63 KB

Committed to DRUPAL-5--2, in #317980.

Attached the patch.

jpmckinney’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Patch (to be ported) » Fixed

See http://bugs.mysql.com/bug.php?id=15610. If node_comment_statistics has no matching row, c.last_comment_timestamp will be NULL, and GREATEST(NULL, 1) will return NULL. Fixed by running COALESCE(c.last_comment_timestamp, 0).

http://drupal.org/cvs?commit=359076
http://drupal.org/cvs?commit=359078

pwolanin’s picture

Version: 6.x-2.x-dev » 6.x-1.x-dev
Status: Needs work » Patch (to be ported)

does this need to be applied to 6.x-1.x? Let's make sure any cross-branch bugs are fixed in all branches.

jpmckinney’s picture

Version: 6.x-2.x-dev » 6.x-1.x-dev

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.