@@ -873,13 +873,15 @@ struct M_EXPORT Database
873
873
const Table &table; // /< the table of the index
874
874
const Attribute &attribute; // /< the indexed attribute
875
875
std::unique_ptr<idx::IndexBase> index; // /< the actual index
876
+ bool is_valid; // /< indicates if the index should be used to answer queries
876
877
877
878
index_entry_type (const char *name, const Table &table, const Attribute &attribute,
878
879
std::unique_ptr<idx::IndexBase> index)
879
880
: name(name)
880
881
, table(table)
881
882
, attribute(attribute)
882
883
, index(std::move(index))
884
+ , is_valid(true )
883
885
{ }
884
886
};
885
887
@@ -986,7 +988,7 @@ struct M_EXPORT Database
986
988
if (it->name == index_name) return true ;
987
989
return false ;
988
990
}
989
- /* * Returns `true` iff there is an index using \p method on \p attribute_name of \p table_name. Throws
991
+ /* * Returns `true` iff there is a valid index using \p method on \p attribute_name of \p table_name. Throws
990
992
* `m::invalid_argument` if a `Table` with the given \p table_name does not exist. Throws `m::invalid_argument` if
991
993
* an `Attribute` with \p attribute_name does not exist in `Table` \p table_name. */
992
994
bool has_index (const char *table_name, const char *attribute_name, idx::IndexMethod method) const {
@@ -997,7 +999,7 @@ struct M_EXPORT Database
997
999
if (not table->has_attribute (attribute_name))
998
1000
throw m::invalid_argument (" Attribute with that name does not exist." );
999
1001
for (auto &entry : indexes_) {
1000
- if (entry.table .name () == table_name and entry.attribute .name == attribute_name and
1002
+ if (entry.is_valid and entry. table .name () == table_name and entry.attribute .name == attribute_name and
1001
1003
entry.index ->method () == method)
1002
1004
{
1003
1005
return true ;
@@ -1014,7 +1016,7 @@ struct M_EXPORT Database
1014
1016
}
1015
1017
throw m::invalid_argument (" Index of that name does not exist." );
1016
1018
}
1017
- /* * Returns an index using \p method on \p attribute_name of \p table_name iff one exists. Throws
1019
+ /* * Returns a valid index using \p method on \p attribute_name of \p table_name iff one exists. Throws
1018
1020
* `m::invalid_argument` if such an index does not exist. Throws `m::invalid_argument` if a `Table` with the given
1019
1021
* \p table_name does not exist. Throws `m::invalid_argument` if an `Attribute` with \p attribute_name does not
1020
1022
* exist in `Table` \p table_name. */
@@ -1026,15 +1028,24 @@ struct M_EXPORT Database
1026
1028
if (not table->has_attribute (attribute_name))
1027
1029
throw m::invalid_argument (" Attribute with that name does not exist." );
1028
1030
for (auto &entry : indexes_) {
1029
- if (entry.table .name () == table_name and entry.attribute .name == attribute_name and
1031
+ if (entry.is_valid and entry. table .name () == table_name and entry.attribute .name == attribute_name and
1030
1032
entry.index ->method () == method)
1031
1033
{
1032
1034
return *entry.index ;
1033
1035
}
1034
1036
}
1035
1037
throw m::invalid_argument (" Index of that method on that attribute of that table does not exist." );
1036
1038
}
1037
-
1039
+ /* * Invalidates all indexes on attributes of `Table` \p table_name s.t. they are no longer used to answer queries.
1040
+ * Throws `m_invalid_argument` if a `Table` with the given \p table_name does not exist. */
1041
+ void invalidate_indexes (const char *table_name) {
1042
+ if (not has_table (table_name))
1043
+ throw m::invalid_argument (" Table with that name does not exist." );
1044
+ for (auto &entry : indexes_) {
1045
+ if (entry.table .name () == table_name)
1046
+ entry.is_valid = false ;
1047
+ }
1048
+ }
1038
1049
};
1039
1050
1040
1051
}
0 commit comments