diff --git a/xapian-core/backends/glass/glass_postlist.cc b/xapian-core/backends/glass/glass_postlist.cc
index a7f6fa535ee6..774521fd179b 100644
--- a/xapian-core/backends/glass/glass_postlist.cc
+++ b/xapian-core/backends/glass/glass_postlist.cc
@@ -701,6 +701,7 @@ GlassPostList::GlassPostList(intrusive_ptr<const GlassDatabase> this_db_,
           this_db(keep_reference ? this_db_ : nullptr),
           have_started(false),
           is_at_end(false),
+          all_docs(term_.empty()),
           cursor(this_db_->postlist_table.cursor_get())
 {
     LOGCALL_CTOR(DB, "GlassPostList", this_db_.get() | term_ | keep_reference);
@@ -714,6 +715,7 @@ GlassPostList::GlassPostList(intrusive_ptr<const GlassDatabase> this_db_,
           this_db(this_db_),
           have_started(false),
           is_at_end(false),
+          all_docs(term_.empty()),
           cursor(cursor_)
 {
     LOGCALL_CTOR(DB, "GlassPostList", this_db_.get() | term_ | cursor_);
@@ -814,7 +816,8 @@ GlassPostList::next_chunk()
     const char * keypos = cursor->current_key.data();
     const char * keyend = keypos + cursor->current_key.size();
     // Check we're still in same postlist
-    if (!check_term_in_key_lite(&keypos, keyend, term)) {
+    string_view kterm = all_docs ? string_view() : term;
+    if (!check_term_in_key_lite(&keypos, keyend, kterm)) {
         is_at_end = true;
         throw Xapian::DatabaseCorruptError("Unexpected end of posting list for '" +
                                      term + "'");
@@ -900,13 +903,14 @@ void
 GlassPostList::move_to_chunk_containing(Xapian::docid desired_did)
 {
     LOGCALL_VOID(DB, "GlassPostList::move_to_chunk_containing", desired_did);
-    (void)cursor->find_entry(GlassPostListTable::make_key(term, desired_did));
+    string_view kterm = all_docs ? string_view() : term;
+    (void)cursor->find_entry(GlassPostListTable::make_key(kterm, desired_did));
     Assert(!cursor->after_end());
 
     const char * keypos = cursor->current_key.data();
     const char * keyend = keypos + cursor->current_key.size();
     // Check we're still in same postlist
-    if (!check_term_in_key_lite(&keypos, keyend, term)) {
+    if (!check_term_in_key_lite(&keypos, keyend, kterm)) {
         // This should only happen if the postlist doesn't exist at all.
         is_at_end = true;
         is_last_chunk = true;
diff --git a/xapian-core/backends/glass/glass_postlist.h b/xapian-core/backends/glass/glass_postlist.h
index 2fef145b5266..68f852ba9702 100644
--- a/xapian-core/backends/glass/glass_postlist.h
+++ b/xapian-core/backends/glass/glass_postlist.h
@@ -69,6 +69,16 @@ class GlassPostList : public LeafPostList {
     /// Whether we've run off the end of the list yet.
     bool is_at_end;
 
+    /** Are we iterating all docs?
+     *
+     *  This is true for the GlassPostList for the doc lengths.
+     *
+     *  We also use it for a term which indexes all the documents if we don't
+     *  need wdfs.  We call set_term() so can't just use the term name to
+     *  build keys, etc after construction.
+     */
+    bool all_docs = false;
+
     /// Cursor pointing to current chunk of postlist.
     std::unique_ptr<GlassCursor> cursor;
 
