Use stored procedures to reduce protocol parsing.

Profile says lots of time in MySQL protocol, so reduce it.
And also cache the values that are common.

Obviously, this should cut down the queries a lot in the common case as
well.