Call CHECK_FOR_INTERRUPTS slightly less often when tuplesorting.
authorRobert Haas <rhaas@postgresql.org>
Tue, 14 Feb 2012 17:26:30 +0000 (12:26 -0500)
committerRobert Haas <rhaas@postgresql.org>
Tue, 14 Feb 2012 17:26:30 +0000 (12:26 -0500)
src/backend/utils/sort/qsort_tuple.c
src/backend/utils/sort/tuplesort.c

index b3d75743cda5a640bcc8717c1206a3ffd62dcd32..f751007adaa33f74f88af073c843b4156dc5a31e 100644 (file)
@@ -98,6 +98,7 @@ qsort_tuple(SortTuple *a, size_t n, SortTupleComparator cmp,
                                presorted;
 
 loop:
+       CHECK_FOR_INTERRUPTS();
        if (n < 7)
        {
                for (pm = a + 1; pm < a + n; pm++)
@@ -108,6 +109,7 @@ loop:
        presorted = 1;
        for (pm = a + 1; pm < a + n; pm++)
        {
+               CHECK_FOR_INTERRUPTS();
                if (cmp(pm - 1, pm, state) > 0)
                {
                        presorted = 0;
@@ -137,6 +139,7 @@ loop:
        {
                while (pb <= pc && (r = cmp(pb, a, state)) <= 0)
                {
+                       CHECK_FOR_INTERRUPTS();
                        if (r == 0)
                        {
                                swap(pa, pb);
@@ -146,6 +149,7 @@ loop:
                }
                while (pb <= pc && (r = cmp(pc, a, state)) >= 0)
                {
+                       CHECK_FOR_INTERRUPTS();
                        if (r == 0)
                        {
                                swap(pc, pd);
index 6d7012afb93eb40f07e3d6182e7f357e71e8647c..0dfe9fb9f1279820e56396b1b228d141d5abc149 100644 (file)
@@ -2666,9 +2666,6 @@ comparetup_heap(const SortTuple *a, const SortTuple *b, Tuplesortstate *state)
        int                     nkey;
        int32           compare;
 
-       /* Allow interrupting long sorts */
-       CHECK_FOR_INTERRUPTS();
-
        /* Compare the leading sort key */
        compare = ApplySortComparator(a->datum1, a->isnull1,
                                                                  b->datum1, b->isnull1,
@@ -2810,9 +2807,6 @@ comparetup_cluster(const SortTuple *a, const SortTuple *b,
        int                     nkey;
        int32           compare;
 
-       /* Allow interrupting long sorts */
-       CHECK_FOR_INTERRUPTS();
-
        /* Compare the leading sort key, if it's simple */
        if (state->indexInfo->ii_KeyAttrNumbers[0] != 0)
        {
@@ -3001,9 +2995,6 @@ comparetup_index_btree(const SortTuple *a, const SortTuple *b,
        int                     nkey;
        int32           compare;
 
-       /* Allow interrupting long sorts */
-       CHECK_FOR_INTERRUPTS();
-
        /* Compare the leading sort key */
        compare = inlineApplySortFunction(&scanKey->sk_func, scanKey->sk_flags,
                                                                          scanKey->sk_collation,
@@ -3108,9 +3099,6 @@ comparetup_index_hash(const SortTuple *a, const SortTuple *b,
        IndexTuple      tuple1;
        IndexTuple      tuple2;
 
-       /* Allow interrupting long sorts */
-       CHECK_FOR_INTERRUPTS();
-
        /*
         * Fetch hash keys and mask off bits we don't want to sort by. We know
         * that the first column of the index tuple is the hash key.
@@ -3237,9 +3225,6 @@ reversedirection_index_hash(Tuplesortstate *state)
 static int
 comparetup_datum(const SortTuple *a, const SortTuple *b, Tuplesortstate *state)
 {
-       /* Allow interrupting long sorts */
-       CHECK_FOR_INTERRUPTS();
-
        return ApplySortComparator(a->datum1, a->isnull1,
                                                           b->datum1, b->isnull1,
                                                           state->datumKey);