• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / github_pull_request_279261

11 Oct 2023 02:16PM UTC coverage: 91.624% (+0.06%) from 91.563%
github_pull_request_279261

Pull #6763

Evergreen

finnschiermer
Merge branch 'master' of github.com:realm/realm-core into fsa/enhance-freelist-check
Pull Request #6763: add freelist verification at more points during commit

94332 of 173512 branches covered (0.0%)

124 of 124 new or added lines in 2 files covered. (100.0%)

29 existing lines in 10 files now uncovered.

230660 of 251746 relevant lines covered (91.62%)

6863226.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.18
/src/realm/table_view.cpp
1
/*************************************************************************
2
 *
3
 * Copyright 2016 Realm Inc.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 **************************************************************************/
18

19
#include <realm/table_view.hpp>
20
#include <realm/column_integer.hpp>
21
#include <realm/index_string.hpp>
22
#include <realm/transaction.hpp>
23

24
#include <unordered_set>
25

26
using namespace realm;
27

28
TableView::TableView(TableView& src, Transaction* tr, PayloadPolicy policy_mode)
29
    : m_source_column_key(src.m_source_column_key)
30
{
58,023✔
31
    bool was_in_sync = src.is_in_sync();
58,023✔
32
    if (src.m_query)
58,023✔
33
        m_query = Query(*src.m_query, tr, policy_mode);
57,417✔
34
    m_table = tr->import_copy_of(src.m_table);
58,023✔
35

28,755✔
36
    if (policy_mode == PayloadPolicy::Stay)
58,023✔
37
        was_in_sync = false;
96✔
38

28,755✔
39
    VersionID src_version =
58,023✔
40
        dynamic_cast<Transaction*>(src.m_table->get_parent_group())->get_version_of_current_transaction();
58,023✔
41
    if (src_version != tr->get_version_of_current_transaction())
58,023✔
42
        was_in_sync = false;
18✔
43

28,755✔
44
    m_table = tr->import_copy_of(src.m_table);
58,023✔
45
    m_collection_source = tr->import_copy_of(src.m_collection_source);
58,023✔
46
    if (src.m_source_column_key) {
58,023✔
47
        m_linked_obj = tr->import_copy_of(src.m_linked_obj);
606✔
48
    }
606✔
49

28,755✔
50
    if (was_in_sync)
58,023✔
51
        get_dependencies(m_last_seen_versions);
57,903✔
52

28,755✔
53
    // don't use methods which throw after this point...or m_table_view_key_values will leak
28,755✔
54
    if (policy_mode == PayloadPolicy::Copy && src.m_key_values.is_attached()) {
58,023✔
55
        m_key_values = src.m_key_values;
702✔
56
    }
702✔
57
    else if (policy_mode == PayloadPolicy::Move && src.m_key_values.is_attached())
57,321✔
58
        // Requires that 'src' is a writable object
28,356✔
59
        m_key_values = std::move(src.m_key_values);
57,225✔
60
    else {
96✔
61
        m_key_values.create();
96✔
62
    }
96✔
63
    if (policy_mode == PayloadPolicy::Move) {
58,023✔
64
        src.m_last_seen_versions.clear();
57,225✔
65
    }
57,225✔
66
    m_descriptor_ordering = src.m_descriptor_ordering;
58,023✔
67
    m_limit = src.m_limit;
58,023✔
68
}
58,023✔
69

70
// Aggregates ----------------------------------------------------
71

72
template <typename T, Action AggregateOpType>
73
struct Aggregator {
74
};
75

76
template <typename T>
77
struct Aggregator<T, act_Sum> {
78
    using AggType = typename aggregate_operations::Sum<typename util::RemoveOptional<T>::type>;
79
};
80

81
template <typename T>
82
struct Aggregator<T, act_Average> {
83
    using AggType = typename aggregate_operations::Average<typename util::RemoveOptional<T>::type>;
84
};
85

86
template <typename T>
87
struct Aggregator<T, act_Min> {
88
    using AggType = typename aggregate_operations::Minimum<typename util::RemoveOptional<T>::type>;
89
};
90

91
template <typename T>
92
struct Aggregator<T, act_Max> {
93
    using AggType = typename aggregate_operations::Maximum<typename util::RemoveOptional<T>::type>;
94
};
95

96
template <Action action, typename T>
97
Mixed TableView::aggregate(ColKey column_key, size_t* result_count, ObjKey* return_key) const
98
{
4,230✔
99
    static_assert(action == act_Sum || action == act_Max || action == act_Min || action == act_Average);
4,230✔
100
    REALM_ASSERT(m_table->valid_column(column_key));
4,230!
101

2,115✔
102
    size_t non_nulls = 0;
4,230✔
103
    typename Aggregator<T, action>::AggType agg;
4,230✔
104
    ObjKey last_accumulated_key = null_key;
4,230✔
105
    for (size_t tv_index = 0; tv_index < m_key_values.size(); ++tv_index) {
57,438!
106
        ObjKey key(get_key(tv_index));
53,208✔
107

26,484✔
108
        // skip detached references:
26,484✔
109
        if (key == realm::null_key)
53,208!
110
            continue;
×
111

26,484✔
112
        const Obj obj = m_table->try_get_object(key);
53,208✔
113
        // aggregation must be robust in the face of stale keys:
26,484✔
114
        if (!obj.is_valid())
53,208!
115
            continue;
24✔
116

26,472✔
117
        if (obj.is_null(column_key))
53,184!
118
            continue;
8,718✔
119

22,428✔
120
        auto v = obj.get<T>(column_key);
44,466✔
121
        if (agg.accumulate(v)) {
44,466!
122
            ++non_nulls;
30,429✔
123
            if constexpr (action == act_Min || action == act_Max) {
30,429✔
124
                last_accumulated_key = key;
15,033✔
125
            }
15,033✔
126
        }
30,429✔
127
    }
44,466✔
128

2,115✔
129
    if (result_count)
4,230!
130
        *result_count = non_nulls;
696✔
131

2,115✔
132
    if constexpr (action == act_Max || action == act_Min) {
4,230✔
133
        if (return_key) {
2,532!
134
            *return_key = last_accumulated_key;
2,040✔
135
        }
2,040✔
136
    }
2,532✔
137
    else {
1,698✔
138
        static_cast<void>(last_accumulated_key);
1,698✔
139
        static_cast<void>(return_key);
1,698✔
140
    }
1,698✔
141

2,115✔
142
    if (!agg.is_null()) {
4,230!
143
        return agg.result();
3,330✔
144
    }
3,330✔
145
    if (action == act_Sum) {
900✔
146
        if (std::is_same_v<T, Mixed>) {
×
147
            return Decimal128{0};
×
148
        }
×
149
        return T{};
×
150
    }
×
151
    return Mixed();
900✔
152
}
900✔
153

154
template <typename T>
155
size_t TableView::aggregate_count(ColKey column_key, T count_target) const
156
{
48✔
157
    REALM_ASSERT(m_table->valid_column(column_key));
48!
158

24✔
159
    if ((m_key_values.size()) == 0) {
48!
160
        return {};
×
161
    }
×
162

24✔
163
    size_t cnt = 0;
48✔
164
    for (size_t tv_index = 0; tv_index < m_key_values.size(); ++tv_index) {
240!
165
        ObjKey key(get_key(tv_index));
192✔
166

96✔
167
        // skip detached references:
96✔
168
        if (key == realm::null_key)
192!
169
            continue;
×
170

96✔
171
        const Obj obj = m_table->try_get_object(key);
192✔
172
        if (!obj.is_valid())
192!
173
            continue;
×
174

96✔
175
        auto v = obj.get<T>(column_key);
192✔
176
        if (v == count_target) {
192!
177
            cnt++;
102✔
178
        }
102✔
179
    }
192✔
180

24✔
181
    return cnt;
48✔
182
}
48✔
183

184
// Count
185
size_t TableView::count_int(ColKey column_key, int64_t target) const
186
{
12✔
187
    if (m_table->is_nullable(column_key))
12✔
188
        return aggregate_count<util::Optional<int64_t>>(column_key, target);
×
189
    else
12✔
190
        return aggregate_count<int64_t>(column_key, target);
12✔
191
}
12✔
192
size_t TableView::count_float(ColKey column_key, float target) const
193
{
12✔
194
    return aggregate_count<float>(column_key, target);
12✔
195
}
12✔
196
size_t TableView::count_double(ColKey column_key, double target) const
197
{
12✔
198
    return aggregate_count<double>(column_key, target);
12✔
199
}
12✔
200
size_t TableView::count_timestamp(ColKey column_key, Timestamp target) const
201
{
12✔
202
    return aggregate_count<Timestamp>(column_key, target);
12✔
203
}
12✔
204
size_t TableView::count_decimal(ColKey column_key, Decimal128 target) const
205
{
×
206
    return aggregate_count<Decimal128>(column_key, target);
×
207
}
×
208
size_t TableView::count_mixed(ColKey column_key, Mixed target) const
209
{
×
210
    return aggregate_count<Mixed>(column_key, target);
×
211
}
×
212

213
template <Action action>
214
std::optional<Mixed> TableView::aggregate(ColKey column_key, size_t* count, ObjKey* return_key) const
215
{
4,422✔
216
    static_assert(action == act_Sum || action == act_Max || action == act_Min || action == act_Average);
4,422✔
217
    m_table->check_column(column_key);
4,422✔
218
    if (column_key.is_collection()) {
4,422✔
219
        return std::nullopt;
48✔
220
    }
48✔
221

2,187✔
222
    switch (column_key.get_type()) {
4,374✔
223
        case col_type_Int:
1,596✔
224
            if (m_table->is_nullable(column_key))
1,596✔
225
                return aggregate<action, util::Optional<int64_t>>(column_key, count, return_key);
1,470✔
226
            return aggregate<action, int64_t>(column_key, count, return_key);
126✔
227
        case col_type_Float:
1,506✔
228
            return aggregate<action, float>(column_key, count, return_key);
1,506✔
229
        case col_type_Double:
342✔
230
            return aggregate<action, double>(column_key, count, return_key);
342✔
231
        case col_type_Timestamp:
99✔
232
            if constexpr (action == act_Min || action == act_Max) {
858✔
233
                return aggregate<action, Timestamp>(column_key, count, return_key);
786✔
234
            }
786✔
235
            break;
×
236
        case col_type_Decimal:
✔
237
            return aggregate<action, Decimal128>(column_key, count, return_key);
×
238
        case col_type_Mixed:
✔
239
            return aggregate<action, Mixed>(column_key, count, return_key);
×
240
        default:
✔
241
            break;
×
242
    }
72✔
243
    return util::none;
72✔
244
}
72✔
245

246
util::Optional<Mixed> TableView::min(ColKey column_key, ObjKey* return_key) const
247
{
1,290✔
248
    return aggregate<act_Min>(column_key, nullptr, return_key);
1,290✔
249
}
1,290✔
250

251
util::Optional<Mixed> TableView::max(ColKey column_key, ObjKey* return_key) const
252
{
1,302✔
253
    return aggregate<act_Max>(column_key, nullptr, return_key);
1,302✔
254
}
1,302✔
255

256
util::Optional<Mixed> TableView::sum(ColKey column_key) const
257
{
900✔
258
    return aggregate<act_Sum>(column_key, nullptr, nullptr);
900✔
259
}
900✔
260

261
util::Optional<Mixed> TableView::avg(ColKey column_key, size_t* value_count) const
262
{
930✔
263
    return aggregate<act_Average>(column_key, value_count, nullptr);
930✔
264
}
930✔
265

266
void TableView::to_json(std::ostream& out, size_t link_depth, const std::map<std::string, std::string>& renames,
267
                        JSONOutputMode mode) const
268
{
60✔
269
    // Represent table as list of objects
30✔
270
    out << "[";
60✔
271

30✔
272
    const size_t row_count = size();
60✔
273
    bool first = true;
60✔
274
    for (size_t r = 0; r < row_count; ++r) {
540✔
275
        if (ObjKey key = get_key(r)) {
480✔
276
            if (first) {
480✔
277
                first = false;
60✔
278
            }
60✔
279
            else {
420✔
280
                out << ",";
420✔
281
            }
420✔
282
            m_table->get_object(key).to_json(out, link_depth, renames, mode);
480✔
283
        }
480✔
284
    }
480✔
285

30✔
286
    out << "]";
60✔
287
}
60✔
288

289
bool TableView::depends_on_deleted_object() const
290
{
42✔
291
    if (m_collection_source) {
42✔
292
        return !m_collection_source->get_owning_obj().is_valid();
12✔
293
    }
12✔
294

15✔
295
    if (m_source_column_key && !m_linked_obj.is_valid()) {
30✔
296
        return true;
12✔
297
    }
12✔
298
    else if (m_query && m_query->m_source_table_view) {
18✔
299
        return m_query->m_source_table_view->depends_on_deleted_object();
6✔
300
    }
6✔
301
    return false;
12✔
302
}
12✔
303

304
void TableView::get_dependencies(TableVersions& ret) const
305
{
1,695,774✔
306
    auto table = m_table ? m_table.unchecked_ptr() : nullptr;
2,148,473,944✔
307
    if (m_source_column_key && m_linked_obj) {
1,695,774✔
308
        // m_source_column_key is set when this TableView was created by Table::get_backlink_view().
1,056✔
309
        if (auto linked_table = m_linked_obj.get_table()) {
2,112✔
310
            ret.emplace_back(linked_table->get_key(), linked_table->get_content_version());
2,112✔
311
        }
2,112✔
312
    }
2,112✔
313
    else if (m_query) {
1,899,768✔
314
        m_query->get_outside_versions(ret);
1,894,647✔
315
    }
1,894,647✔
316
    else {
2,147,488,768✔
317
        // This TableView was created by Table::get_distinct_view() or get_sorted_view() on collections
2,147,483,647✔
318
        ret.emplace_back(table->get_key(), table->get_content_version());
2,147,488,768✔
319
    }
2,147,488,768✔
320

702,189✔
321
    // Finally add dependencies from sort/distinct
702,189✔
322
    if (table) {
1,931,460✔
323
        m_descriptor_ordering.get_versions(table->get_parent_group(), ret);
1,931,460✔
324
    }
1,931,460✔
325
}
1,695,774✔
326

327
bool TableView::is_in_sync() const
328
{
246,705✔
329
    return m_table && !has_changed();
246,705✔
330
}
246,705✔
331

332
void TableView::sync_if_needed() const
333
{
136,011✔
334
    if (!is_in_sync()) {
136,011✔
335
        // FIXME: Is this a reasonable handling of constness?
28,074✔
336
        const_cast<TableView*>(this)->do_sync();
56,853✔
337
    }
56,853✔
338
}
136,011✔
339

340
void TableView::update_query(const Query& q)
341
{
12✔
342
    REALM_ASSERT(m_query);
12✔
343
    REALM_ASSERT(m_query->m_table);
12✔
344
    REALM_ASSERT(m_query->m_table == q.m_table);
12✔
345

6✔
346
    m_query = q;
12✔
347
    do_sync();
12✔
348
}
12✔
349

350
void TableView::clear()
351
{
4,767✔
352
    m_table.check();
4,767✔
353

2,385✔
354
    // If distinct is applied then removing an object may leave us out of sync
2,385✔
355
    // if there's another object with the same value in the distinct column
2,385✔
356
    // as the removed object
2,385✔
357
    bool sync_to_keep =
4,767✔
358
        m_last_seen_versions == get_dependency_versions() && !m_descriptor_ordering.will_apply_distinct();
4,767✔
359

2,385✔
360
    // Remove all invalid keys
2,385✔
361
    auto it = std::remove_if(m_key_values.begin(), m_key_values.end(), [this](const ObjKey& key) {
2,511,732✔
362
        return !m_table->is_valid(key);
2,511,732✔
363
    });
2,511,732✔
364
    m_key_values.erase(it, m_key_values.end());
4,767✔
365

2,385✔
366
    _impl::TableFriend::batch_erase_objects(*get_parent(), m_key_values); // Throws
4,767✔
367

2,385✔
368
    // It is important to not accidentally bring us in sync, if we were
2,385✔
369
    // not in sync to start with:
2,385✔
370
    if (sync_to_keep)
4,767✔
371
        m_last_seen_versions = get_dependency_versions();
4,749✔
372
}
4,767✔
373

374
void TableView::distinct(ColKey column)
375
{
144✔
376
    distinct(DistinctDescriptor({{column}}));
144✔
377
}
144✔
378

379
/// Remove rows that are duplicated with respect to the column set passed as argument.
380
/// Will keep original sorting order so that you can both have a distinct and sorted view.
381
void TableView::distinct(DistinctDescriptor columns)
382
{
432✔
383
    m_descriptor_ordering.append_distinct(std::move(columns));
432✔
384
    m_descriptor_ordering.collect_dependencies(m_table.unchecked_ptr());
432✔
385

216✔
386
    do_sync();
432✔
387
}
432✔
388

389
void TableView::limit(LimitDescriptor lim)
390
{
12✔
391
    m_descriptor_ordering.append_limit(std::move(lim));
12✔
392
    do_sync();
12✔
393
}
12✔
394

395
void TableView::filter(FilterDescriptor filter)
396
{
12✔
397
    m_descriptor_ordering.append_filter(std::move(filter));
12✔
398
    do_sync();
12✔
399
}
12✔
400

401
void TableView::apply_descriptor_ordering(const DescriptorOrdering& new_ordering)
402
{
41,772✔
403
    m_descriptor_ordering = new_ordering;
41,772✔
404
    m_descriptor_ordering.collect_dependencies(m_table.unchecked_ptr());
41,772✔
405

21,294✔
406
    do_sync();
41,772✔
407
}
41,772✔
408

409
std::string TableView::get_descriptor_ordering_description() const
410
{
18✔
411
    return m_descriptor_ordering.get_description(m_table);
18✔
412
}
18✔
413

414
// Sort according to one column
415
void TableView::sort(ColKey column, bool ascending)
416
{
450✔
417
    sort(SortDescriptor({{column}}, {ascending}));
450✔
418
}
450✔
419

420
// Sort according to multiple columns, user specified order on each column
421
void TableView::sort(SortDescriptor order)
422
{
1,020✔
423
    m_descriptor_ordering.append_sort(std::move(order), SortDescriptor::MergeMode::prepend);
1,020✔
424
    m_descriptor_ordering.collect_dependencies(m_table.unchecked_ptr());
1,020✔
425

510✔
426
    apply_descriptors(m_descriptor_ordering);
1,020✔
427
}
1,020✔
428

429

430
void TableView::do_sync()
431
{
1,582,956✔
432
    util::CriticalSection cs(m_race_detector);
1,582,956✔
433
    // This TableView can be "born" from 4 different sources:
761,199✔
434
    // - LinkView
761,199✔
435
    // - Query::find_all()
761,199✔
436
    // - Table::get_distinct_view()
761,199✔
437
    // - Table::get_backlink_view()
761,199✔
438
    // Here we sync with the respective source.
761,199✔
439
    m_last_seen_versions.clear();
1,582,956✔
440

761,199✔
441
    if (m_collection_source) {
1,582,956✔
442
        m_key_values.clear();
102✔
443
        auto sz = m_collection_source->size();
102✔
444
        for (size_t i = 0; i < sz; i++) {
330✔
445
            m_key_values.add(m_collection_source->get_key(i));
228✔
446
        }
228✔
447
    }
102✔
448
    else if (m_source_column_key) {
1,582,854✔
449
        m_key_values.clear();
756✔
450
        if (m_table && m_linked_obj.is_valid()) {
756✔
451
            if (m_table->valid_column(m_source_column_key)) { // return empty result, if column has been removed
744✔
452
                ColKey backlink_col = m_table->get_opposite_column(m_source_column_key);
738✔
453
                REALM_ASSERT(backlink_col);
738✔
454
                auto backlinks = m_linked_obj.get_all_backlinks(backlink_col);
738✔
455
                for (auto k : backlinks) {
723✔
456
                    m_key_values.add(k);
708✔
457
                }
708✔
458
            }
738✔
459
        }
744✔
460
    }
756✔
461
    // FIXME: Unimplemented for link to a column
760,770✔
462
    else {
1,582,098✔
463
        REALM_ASSERT(m_query);
1,582,098✔
464
        m_query->m_table.check();
1,582,098✔
465

760,770✔
466
        // valid query, so clear earlier results and reexecute it.
760,770✔
467
        if (m_key_values.is_attached())
1,582,098✔
468
            m_key_values.clear();
1,491,348✔
469
        else
90,750✔
470
            m_key_values.create();
90,750✔
471

760,770✔
472
        if (m_query->m_view)
1,582,098✔
473
            m_query->m_view->sync_if_needed();
1,101✔
474
        size_t limit = m_limit;
1,582,098✔
475
        if (!m_descriptor_ordering.is_empty()) {
1,582,098✔
476
            auto type = m_descriptor_ordering[0]->get_type();
35,676✔
477
            if (type == DescriptorType::Limit) {
35,676✔
478
                size_t l = static_cast<const LimitDescriptor*>(m_descriptor_ordering[0])->get_limit();
138✔
479
                if (l < limit)
138✔
480
                    limit = l;
138✔
481
            }
138✔
482
        }
35,676✔
483
        QueryStateFindAll<std::vector<ObjKey>> st(m_key_values, limit);
1,582,098✔
484
        m_query->do_find_all(st);
1,582,098✔
485
    }
1,582,098✔
486

761,199✔
487
    apply_descriptors(m_descriptor_ordering);
1,582,956✔
488

761,199✔
489
    get_dependencies(m_last_seen_versions);
1,582,956✔
490
}
1,582,956✔
491

492
void TableView::apply_descriptors(const DescriptorOrdering& ordering)
493
{
1,595,706✔
494
    if (ordering.is_empty())
1,595,706✔
495
        return;
1,624,494✔
496
    size_t sz = size();
2,147,502,610✔
497
    if (sz == 0)
2,147,502,610✔
498
        return;
18,123✔
499

2,147,483,647✔
500
    // Gather the current rows into a container we can use std algorithms on
2,147,483,647✔
501
    size_t detached_ref_count = 0;
2,147,493,943✔
502
    BaseDescriptor::IndexPairs index_pairs;
2,147,493,943✔
503
    bool using_indexpairs = false;
2,147,493,943✔
504

2,147,483,647✔
505
    auto apply_indexpairs = [&] {
2,147,492,848✔
506
        m_key_values.clear();
18,429✔
507
        for (auto& pair : index_pairs) {
186,609✔
508
            m_key_values.add(pair.key_for_object);
186,609✔
509
        }
186,609✔
510
        for (size_t t = 0; t < detached_ref_count; ++t)
18,429✔
511
            m_key_values.add(null_key);
×
512
        using_indexpairs = false;
18,429✔
513
    };
18,429✔
514

2,147,483,647✔
515
    auto use_indexpairs = [&] {
2,147,492,860✔
516
        index_pairs.reserve(sz);
18,453✔
517
        index_pairs.clear();
18,453✔
518
        // always put any detached refs at the end of the sort
9,240✔
519
        // FIXME: reconsider if this is the right thing to do
9,240✔
520
        // FIXME: consider specialized implementations in derived classes
9,240✔
521
        // (handling detached refs is not required in linkviews)
9,240✔
522
        for (size_t t = 0; t < sz; t++) {
267,387✔
523
            ObjKey key = get_key(t);
248,934✔
524
            if (m_table->is_valid(key)) {
248,934✔
525
                index_pairs.emplace_back(key, t);
248,934✔
526
            }
248,934✔
UNCOV
527
            else
×
UNCOV
528
                ++detached_ref_count;
×
529
        }
248,934✔
530
        using_indexpairs = true;
18,453✔
531
    };
18,453✔
532

2,147,483,647✔
533
    const int num_descriptors = int(ordering.size());
2,147,493,943✔
534
    for (int desc_ndx = 0; desc_ndx < num_descriptors; ++desc_ndx) {
2,147,504,506✔
535
        const BaseDescriptor* base_descr = ordering[desc_ndx];
21,171✔
536
        const BaseDescriptor* next = ((desc_ndx + 1) < num_descriptors) ? ordering[desc_ndx + 1] : nullptr;
19,869✔
537

10,608✔
538
        // Some descriptors, like Sort and Distinct, needs us to gather the current rows
10,608✔
539
        // into a container we can use std algorithms on
10,608✔
540
        if (base_descr->need_indexpair()) {
21,171✔
541
            if (!using_indexpairs) {
19,059✔
542
                use_indexpairs();
18,453✔
543
            }
18,453✔
544

9,543✔
545
            BaseDescriptor::Sorter predicate = base_descr->sorter(*m_table, index_pairs);
19,059✔
546

9,543✔
547
            // Sorting can be specified by multiple columns, so that if two entries in the first column are
9,543✔
548
            // identical, then the rows are ordered according to the second column, and so forth. For the
9,543✔
549
            // first column, we cache all the payload of fields of the view in a std::vector<Mixed>
9,543✔
550
            predicate.cache_first_column(index_pairs);
19,059✔
551

9,543✔
552
            base_descr->execute(index_pairs, predicate, next);
19,059✔
553
        }
19,059✔
554
        else {
2,112✔
555
            if (using_indexpairs) {
2,112✔
556
                apply_indexpairs();
1,884✔
557
            }
1,884✔
558
            base_descr->execute(*m_table, m_key_values, next);
2,112✔
559
            sz = size();
2,112✔
560
        }
2,112✔
561
    }
21,171✔
562
    // Apply the results
2,147,483,647✔
563
    if (using_indexpairs) {
2,147,493,943✔
564
        apply_indexpairs();
16,545✔
565
    }
16,545✔
566
}
2,147,493,943✔
567

568
bool TableView::is_in_table_order() const
569
{
2,598✔
570
    if (!m_table) {
2,598✔
571
        return false;
6✔
572
    }
6✔
573
    else if (m_collection_source) {
2,592✔
574
        return false;
6✔
575
    }
6✔
576
    else if (m_source_column_key) {
2,586✔
577
        return false;
6✔
578
    }
6✔
579
    else if (!m_query) {
2,580✔
580
        return false;
66✔
581
    }
66✔
582
    else {
2,514✔
583
        m_query->m_table.check();
2,514✔
584
        return m_query->produces_results_in_table_order() && !m_descriptor_ordering.will_apply_sort();
2,514✔
585
    }
2,514✔
586
}
2,598✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc