 
 
     stringifyQs: (qs) ->
-        qs = _.clone qs
-        if qs.fields is undefined or _.isEmpty qs.fields
-            delete qs.fields
-        if qs.sort is undefined or _.isEmpty qs.sort
-            delete qs.sort
-        if not qs.limit
-            delete qs.limit
-        if not qs.skip
-            delete qs.skip
-
-        EJSON.stringify
-            modelName: qs.modelName
-            selector: @_getCanonical qs.selector
-            fields: @_getCanonical qs.fields
-            sort: @_getCanonical qs.sort
-            limit: qs.limit
-            skip: qs.skip
+        EJSON.stringify @getQsCanonicalForm qs
 
 
     tryQsPairwiseMerge: (a, b) ->
         return null if a.modelName isnt b.modelName
+        return null if not EJSON.equals a.sort, b.sort
 
         null

        for modelName, inclusionSetById of inclusionSetByModelInstance
            idsByInclusionSetString = {} # inclusionSetString: [instanceIds]
            for instanceId, inclusionSet of inclusionSetById
                inclusionSetString = EJSON.stringify @_getCanonical inclusionSet
                idsByInclusionSetString[inclusionSetString] ?= []
                idsByInclusionSetString[inclusionSetString].push instanceId




        mergedQuerySpecs


    getQsCanonicalForm: (qs) ->
        # Returns an equivalent querySpec but in "canonical form"
        # so two querySpecs written with minor differences can
        # be fingerprinted by their J.fetching.stringifyQs value

        qs = _.clone qs

        qs.selector = @_getCanonicalSelector qs.selector

        if qs.fields is undefined or _.isEmpty qs.fields
            qs.fields = undefined
        else
            projection = {}
            for projectionKey in J.util.sortByKey _.keys qs.fields
                projection[projectionKey] = qs.fields[projectionKey]
            qs.fields = projection

        if qs.sort is undefined or _.isEmpty qs.sort
            qs.sort = undefined

        if qs.limit is 0 or not qs.limit?
            qs.limit = undefined

        if qs.skip is 0 or not qs.skip?
            qs.skip = undefined

        # This establishes the canonical order of the QS fields
        J.util.withoutUndefined
            modelName: qs.modelName
            selector: qs.selector
            fields: qs.fields
            sort: qs.sort
            limit: qs.limit
            skip: qs.skip


    isQueryReady: (qs) ->
