Hi Marin,

I haven't tested the patch below yet... and I'm a bit uncertain about the first if(). It will do the right thing in principle but does it produce correct SQL syntax? I'll try to test tonight or tomorrow night, if you can't do it sooner.

Arnt

diff --git a/server/selector.cpp b/server/selector.cpp
index 1b68a2a..c54fcc3 100644
--- a/server/selector.cpp
+++ b/server/selector.cpp
@@ -1538,6 +1538,21 @@ EString Selector::whereSet( const IntegerSet & s )

    uint u = placeHolder();
    uint c = s.count();
+ + IntegerSet existing = s.intersection( d->session->messages() );
+    if ( existing.count() == d->session->messages().count() ) {
+        // matches all messages in mailbox
+        return "true";
+    }
+
+    if ( existing.count() == s.count() && existing.count() > 64 ) {
+        // matches a largish range
+        uint u2 = placeHolder();
+        root()->d->query->bind( u, s.smallest() );
+        root()->d->query->bind( u2, s.largest() );
+        return "(" + mm() + ".uid>=$" + fn( u ) +
+            " and " + mm() + ".uid<=$" + fn( u2 ) + ")";
+    }

    if ( c > 2 ) {
        root()->d->query->bind( u, s );

Reply via email to