## Summary
<!--Explain briefly what goes wrong and explain why you believe this is a bug and not the intended behavior of SQLite (if it is not a crash).-->**No review yet**

## Minimized query

```sql
CREATE TABLE T (
  A VARCHAR(20),
  B VARCHAR(10),
  PRIMARY KEY (A, B)
);
INSERT INTO T VALUES ('a', 'p');
INSERT INTO T VALUES ('a', 'q');
INSERT INTO T VALUES ('b', 'q');
INSERT INTO T VALUES ('c', 'r');
INSERT INTO T VALUES ('b', 'r');
INSERT INTO T VALUES ('b', 't');
SELECT B, COUNT(DISTINCT A) AS D FROM T GROUP BY B ORDER BY D DESC, B ASC;
PRAGMA cache_size;
ATTACH DATABASE ':memory:' AS aux81;
ATTACH DATABASE ':memory:' AS aux65;
PRAGMA busy_timeout;
BEGIN IMMEDIATE;
PRAGMA pragma_list;
CREATE VIRTUAL TABLE /* .auth */ t0 USING fts4("x",
"y", "z");
DROP TABLE t0;
ROLLBACK;
DETACH DATABASE aux65;
DETACH DATABASE aux81;
ATTACH DATABASE ':memory:' AS aux81;
ATTACH DATABASE ':memory:' AS aux65;
PRAGMA busy_timeout;
BEGIN IMMEDIATE;
PRAGMA pragma_list; /* PRAGMA parser_trace = TRUE; */ CREATE VIRTUAL TABLE /* .auth */ t0 USING fts4("x",
"y", "z");
DROP TABLE t0;
ROLLBACK;
DETACH DATABASE aux65;
DETACH DATABASE aux81;
ATTACH DATABASE ':memory:' AS aux81;
ATTACH DATABASE ':memory:' AS aux65;
PRAGMA busy_timeout;
BEGIN IMMEDIATE;
PRAGMA pragma_list;
CREATE VIRTUAL TABLE /* .auth */ t0 USING fts4("x",
"y", "z");
DROP TABLE t0;
ROLLBACK;
DETACH DATABASE aux65;
DETACH DATABASE aux81;
ATTACH DATABASE ':memory:' AS aux81;
ATTACH DATABASE ':memory:' AS aux65;
PRAGMA busy_timeout;
BEGIN IMMEDIATE;
PRAGMA pragma_list;
CREATE VIRTUAL TABLE /* .auth */ t0 USING fts4("x",
"y", "z");
DROP TABLE t0;
ROLLBACK;
DETACH DATABASE aux65;
DETACH DATABASE aux81;
ATTACH DATABASE ':memory:' AS aux81;
ATTACH DATABASE ':memory:' AS aux65;
PRAGMA busy_timeout;
BEGIN IMMEDIATE;
PRAGMA pragma_list;
CREATE VIRTUAL TABLE /* .auth */ t0 USING fts4("x",
"y", "z");
DROP TABLE t0;
ROLLBACK;
DETACH DATABASE aux65;
DETACH DATABASE aux81;

PRAGMA collation_list;
UPDATE T SET B = '' WHERE B BETWEEN 0 AND 100 RETURNING *;
```

## Actual output

```sql
q|2
r|2
p|1
t|1
-2000
0
analysis_limit
application_id
auto_vacuum
automatic_index
busy_timeout
cache_size
cache_spill
case_sensitive_like
cell_size_check
checkpoint_fullfsync
collation_list
compile_options
count_changes
data_version
database_list
default_cache_size
defer_foreign_keys
empty_result_callbacks
encoding
foreign_key_check
foreign_key_list
foreign_keys
freelist_count
full_column_names
fullfsync
function_list
hard_heap_limit
ignore_check_constraints
incremental_vacuum
index_info
index_list
index_xinfo
integrity_check
journal_mode
journal_size_limit
legacy_alter_table
locking_mode
max_page_count
mmap_size
module_list
optimize
page_count
page_size
pragma_list
query_only
quick_check
read_uncommitted
recursive_triggers
reverse_unordered_selects
schema_version
secure_delete
short_column_names
shrink_memory
soft_heap_limit
synchronous
table_info
table_list
table_xinfo
temp_store
temp_store_directory
threads
trusted_schema
user_version
wal_autocheckpoint
wal_checkpoint
writable_schema
0
analysis_limit
application_id
auto_vacuum
automatic_index
busy_timeout
cache_size
cache_spill
case_sensitive_like
cell_size_check
checkpoint_fullfsync
collation_list
compile_options
count_changes
data_version
database_list
default_cache_size
defer_foreign_keys
empty_result_callbacks
encoding
foreign_key_check
foreign_key_list
foreign_keys
freelist_count
full_column_names
fullfsync
function_list
hard_heap_limit
ignore_check_constraints
incremental_vacuum
index_info
index_list
index_xinfo
integrity_check
journal_mode
journal_size_limit
legacy_alter_table
locking_mode
max_page_count
mmap_size
module_list
optimize
page_count
page_size
pragma_list
query_only
quick_check
read_uncommitted
recursive_triggers
reverse_unordered_selects
schema_version
secure_delete
short_column_names
shrink_memory
soft_heap_limit
synchronous
table_info
table_list
table_xinfo
temp_store
temp_store_directory
threads
trusted_schema
user_version
wal_autocheckpoint
wal_checkpoint
writable_schema
0
analysis_limit
application_id
auto_vacuum
automatic_index
busy_timeout
cache_size
cache_spill
case_sensitive_like
cell_size_check
checkpoint_fullfsync
collation_list
compile_options
count_changes
data_version
database_list
default_cache_size
defer_foreign_keys
empty_result_callbacks
encoding
foreign_key_check
foreign_key_list
foreign_keys
freelist_count
full_column_names
fullfsync
function_list
hard_heap_limit
ignore_check_constraints
incremental_vacuum
index_info
index_list
index_xinfo
integrity_check
journal_mode
journal_size_limit
legacy_alter_table
locking_mode
max_page_count
mmap_size
module_list
optimize
page_count
page_size
pragma_list
query_only
quick_check
read_uncommitted
recursive_triggers
reverse_unordered_selects
schema_version
secure_delete
short_column_names
shrink_memory
soft_heap_limit
synchronous
table_info
table_list
table_xinfo
temp_store
temp_store_directory
threads
trusted_schema
user_version
wal_autocheckpoint
wal_checkpoint
writable_schema
0
analysis_limit
application_id
auto_vacuum
automatic_index
busy_timeout
cache_size
cache_spill
case_sensitive_like
cell_size_check
checkpoint_fullfsync
collation_list
compile_options
count_changes
data_version
database_list
default_cache_size
defer_foreign_keys
empty_result_callbacks
encoding
foreign_key_check
foreign_key_list
foreign_keys
freelist_count
full_column_names
fullfsync
function_list
hard_heap_limit
ignore_check_constraints
incremental_vacuum
index_info
index_list
index_xinfo
integrity_check
journal_mode
journal_size_limit
legacy_alter_table
locking_mode
max_page_count
mmap_size
module_list
optimize
page_count
page_size
pragma_list
query_only
quick_check
read_uncommitted
recursive_triggers
reverse_unordered_selects
schema_version
secure_delete
short_column_names
shrink_memory
soft_heap_limit
synchronous
table_info
table_list
table_xinfo
temp_store
temp_store_directory
threads
trusted_schema
user_version
wal_autocheckpoint
wal_checkpoint
writable_schema
0
analysis_limit
application_id
auto_vacuum
automatic_index
busy_timeout
cache_size
cache_spill
case_sensitive_like
cell_size_check
checkpoint_fullfsync
collation_list
compile_options
count_changes
data_version
database_list
default_cache_size
defer_foreign_keys
empty_result_callbacks
encoding
foreign_key_check
foreign_key_list
foreign_keys
freelist_count
full_column_names
fullfsync
function_list
hard_heap_limit
ignore_check_constraints
incremental_vacuum
index_info
index_list
index_xinfo
integrity_check
journal_mode
journal_size_limit
legacy_alter_table
locking_mode
max_page_count
mmap_size
module_list
optimize
page_count
page_size
pragma_list
query_only
quick_check
read_uncommitted
recursive_triggers
reverse_unordered_selects
schema_version
secure_delete
short_column_names
shrink_memory
soft_heap_limit
synchronous
table_info
table_list
table_xinfo
temp_store
temp_store_directory
threads
trusted_schema
user_version
wal_autocheckpoint
wal_checkpoint
writable_schema
0|decimal
1|uint
2|RTRIM
3|NOCASE
4|BINARY
```

## Expectation

```sql
q|2
r|2
p|1
t|1
-2000
0
analysis_limit
application_id
auto_vacuum
automatic_index
busy_timeout
cache_size
cache_spill
case_sensitive_like
cell_size_check
checkpoint_fullfsync
collation_list
compile_options
count_changes
data_version
database_list
default_cache_size
defer_foreign_keys
empty_result_callbacks
encoding
foreign_key_check
foreign_key_list
foreign_keys
freelist_count
full_column_names
fullfsync
function_list
hard_heap_limit
ignore_check_constraints
incremental_vacuum
index_info
index_list
index_xinfo
integrity_check
journal_mode
journal_size_limit
legacy_alter_table
locking_mode
max_page_count
mmap_size
module_list
optimize
page_count
page_size
pragma_list
query_only
quick_check
read_uncommitted
recursive_triggers
reverse_unordered_selects
schema_version
secure_delete
short_column_names
shrink_memory
soft_heap_limit
synchronous
table_info
table_list
table_xinfo
temp_store
temp_store_directory
threads
trusted_schema
user_version
wal_autocheckpoint
wal_checkpoint
writable_schema
0
analysis_limit
application_id
auto_vacuum
automatic_index
busy_timeout
cache_size
cache_spill
case_sensitive_like
cell_size_check
checkpoint_fullfsync
collation_list
compile_options
count_changes
data_version
database_list
default_cache_size
defer_foreign_keys
empty_result_callbacks
encoding
foreign_key_check
foreign_key_list
foreign_keys
freelist_count
full_column_names
fullfsync
function_list
hard_heap_limit
ignore_check_constraints
incremental_vacuum
index_info
index_list
index_xinfo
integrity_check
journal_mode
journal_size_limit
legacy_alter_table
locking_mode
max_page_count
mmap_size
module_list
optimize
page_count
page_size
pragma_list
query_only
quick_check
read_uncommitted
recursive_triggers
reverse_unordered_selects
schema_version
secure_delete
short_column_names
shrink_memory
soft_heap_limit
synchronous
table_info
table_list
table_xinfo
temp_store
temp_store_directory
threads
trusted_schema
user_version
wal_autocheckpoint
wal_checkpoint
writable_schema
0
analysis_limit
application_id
auto_vacuum
automatic_index
busy_timeout
cache_size
cache_spill
case_sensitive_like
cell_size_check
checkpoint_fullfsync
collation_list
compile_options
count_changes
data_version
database_list
default_cache_size
defer_foreign_keys
empty_result_callbacks
encoding
foreign_key_check
foreign_key_list
foreign_keys
freelist_count
full_column_names
fullfsync
function_list
hard_heap_limit
ignore_check_constraints
incremental_vacuum
index_info
index_list
index_xinfo
integrity_check
journal_mode
journal_size_limit
legacy_alter_table
locking_mode
max_page_count
mmap_size
module_list
optimize
page_count
page_size
pragma_list
query_only
quick_check
read_uncommitted
recursive_triggers
reverse_unordered_selects
schema_version
secure_delete
short_column_names
shrink_memory
soft_heap_limit
synchronous
table_info
table_list
table_xinfo
temp_store
temp_store_directory
threads
trusted_schema
user_version
wal_autocheckpoint
wal_checkpoint
writable_schema
0
analysis_limit
application_id
auto_vacuum
automatic_index
busy_timeout
cache_size
cache_spill
case_sensitive_like
cell_size_check
checkpoint_fullfsync
collation_list
compile_options
count_changes
data_version
database_list
default_cache_size
defer_foreign_keys
empty_result_callbacks
encoding
foreign_key_check
foreign_key_list
foreign_keys
freelist_count
full_column_names
fullfsync
function_list
hard_heap_limit
ignore_check_constraints
incremental_vacuum
index_info
index_list
index_xinfo
integrity_check
journal_mode
journal_size_limit
legacy_alter_table
locking_mode
max_page_count
mmap_size
module_list
optimize
page_count
page_size
pragma_list
query_only
quick_check
read_uncommitted
recursive_triggers
reverse_unordered_selects
schema_version
secure_delete
short_column_names
shrink_memory
soft_heap_limit
synchronous
table_info
table_list
table_xinfo
temp_store
temp_store_directory
threads
trusted_schema
user_version
wal_autocheckpoint
wal_checkpoint
writable_schema
0
analysis_limit
application_id
auto_vacuum
automatic_index
busy_timeout
cache_size
cache_spill
case_sensitive_like
cell_size_check
checkpoint_fullfsync
collation_list
compile_options
count_changes
data_version
database_list
default_cache_size
defer_foreign_keys
empty_result_callbacks
encoding
foreign_key_check
foreign_key_list
foreign_keys
freelist_count
full_column_names
fullfsync
function_list
hard_heap_limit
ignore_check_constraints
incremental_vacuum
index_info
index_list
index_xinfo
integrity_check
journal_mode
journal_size_limit
legacy_alter_table
locking_mode
max_page_count
mmap_size
module_list
optimize
page_count
page_size
pragma_list
query_only
quick_check
read_uncommitted
recursive_triggers
reverse_unordered_selects
schema_version
secure_delete
short_column_names
shrink_memory
soft_heap_limit
synchronous
table_info
table_list
table_xinfo
temp_store
temp_store_directory
threads
trusted_schema
user_version
wal_autocheckpoint
wal_checkpoint
writable_schema
0|decimal
1|BINARY
2|NOCASE
3|RTRIM
4|uint
```

## Flag

```
-memtrace
```

