Fix two (somewhat related) issues with masked tables.

One of them is #916, the other one will be described below.