Add condition to avoid high-load useless session queries - refs BT#7140
Merge remote-tracking branch 'origin/1.9.x' into 1.9.x