﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33138	Tuple comparison for efficient lexicographic ordering on multiple columns	Michal Charemza	nobody	"The below doesn't seem possible without resorting to `extra`

{{{
#!div style=""font-size: 80%""
  {{{#!sql
  WHERE (col_a, col_b) > ('value_a', 'value_b')
  ORDER BY (col_a, col_b)
  }}}
}}}

While this is semantically the same as

{{{
#!div style=""font-size: 80%""
  {{{#!sql
  WHERE col_a > 'value_a' OR (col_a = 'value_a' AND col_b > 'value_b')
  ORDER BY (col_a, col_b)
  }}}
}}}

which can be expressed using the Django ORM, PostgreSQL at least treats these differently in terms of applying indexes. Essentially, the tuple version (from my brief testing) is better in the presence of a multi-column index on `col_a, col_b`: it seems to avoid quite a lot of scanning.

My ultimate use case for this is cursor-based pagination, where the cursor is a tuple of 2 columns: an ""almost"" unique datetime, and a fully unique ID for tie-breakers."	New feature	closed	Database layer (models, ORM)	3.2	Normal	duplicate	QuerySet.extra		Unreviewed	0	0	0	0	0	0
