Sparse matrix indexing with ranges is slow and memory hungry

This fixes the case when a whole column is indexed.  However, indexing
parts of columns still has that problem and needs a bigger rewrite.
Merge pull request #6280 from mauro3/sparse_indexing

WIP: Sparse matrix indexing with ranges is slow and memory hungry