Only writing bindings if contained in select.

Variables in select have a pre-allocated index in the particle.
Added support for DISTINCT select.