Avoid pathologically slow query on mysql 5.1, thanks to Moritz Lenz!

Squashed commit of the following:

commit 13b5de7eaebbc624b8f6f69ac6f4c20eefb51946
Author: Moritz Lenz <mlenz@noris.net>
Date:   Tue Sep 17 11:25:57 2013 +0200

    Test for $Ticket{SolutionTime}

commit e584ad23062092fa220df916dbd5f51a118230d3
Author: Moritz Lenz <mlenz@noris.net>
Date:   Tue Sep 17 11:14:54 2013 +0200

    Handle case of NULL result for MAX(create_time)

commit b0afa6173047f4bef05bcd285a0e5e33e236bc0b
Author: Moritz Lenz <mlenz@noris.net>
Date:   Mon Sep 16 10:53:00 2013 +0200

    Avoid pathologically slow query on mysql 5.1

    With the old SQL, mysql 5.1 uses the index for create_time, which basically
    causes a full table scan. (The query optimizer in mysql 5.5. does better
    though).

    With the new sql, the index for ticket_id is used instead, which is much
    faster.