| 1 | #include "schema.hh" |
| 2 | #include "relmodel.hh" |
| 3 | #include <typeinfo> |
| 4 | |
| 5 | using namespace std; |
| 6 | |
| 7 | void schema::generate_indexes() { |
| 8 | |
| 9 | cerr << "Generating indexes..." ; |
| 10 | |
| 11 | for (auto &type : types) { |
| 12 | assert(type); |
| 13 | for (auto &r : aggregates) { |
| 14 | if (type->consistent(r.restype)) |
| 15 | aggregates_returning_type.insert(pair<sqltype *, routine *>(type, &r)); |
| 16 | } |
| 17 | |
| 18 | for (auto &r : routines) { |
| 19 | if (!type->consistent(r.restype)) |
| 20 | continue; |
| 21 | routines_returning_type.insert(pair<sqltype *, routine *>(type, &r)); |
| 22 | if (!r.argtypes.size()) |
| 23 | parameterless_routines_returning_type.insert(pair<sqltype *, routine *>(type, &r)); |
| 24 | } |
| 25 | |
| 26 | for (auto &t : tables) { |
| 27 | for (auto &c : t.columns()) { |
| 28 | if (type->consistent(c.type)) { |
| 29 | tables_with_columns_of_type.insert(pair<sqltype *, table *>(type, &t)); |
| 30 | break; |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | for (auto &concrete : types) { |
| 36 | if (type->consistent(concrete)) |
| 37 | concrete_type.insert(pair<sqltype *, sqltype *>(type, concrete)); |
| 38 | } |
| 39 | |
| 40 | for (auto &o : operators) { |
| 41 | if (type->consistent(o.result)) |
| 42 | operators_returning_type.insert(pair<sqltype *, op *>(type, &o)); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | for (auto &t : tables) { |
| 47 | if (t.is_base_table) |
| 48 | base_tables.push_back(&t); |
| 49 | } |
| 50 | |
| 51 | cerr << "done." << endl; |
| 52 | |
| 53 | assert(booltype); |
| 54 | assert(inttype); |
| 55 | assert(internaltype); |
| 56 | assert(arraytype); |
| 57 | } |
| 58 | |