MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _fetch_multi_indexes

Method _fetch_multi_indexes

lib/sqlalchemy/dialects/mssql/base.py:4543–4621  ·  lib/sqlalchemy/dialects/mssql/base.py::MSDialect._fetch_multi_indexes

Execute the unified indexes queries for one catalog pass. Runs two Core sys.* selects (index metadata + index columns), grouped by table. Used for both the main-DB pass and the tempdb pass (with ``schema_translate_map={"sys": "tempdb.sys"}`` applied).

(
        self, connection, owner, names, schema, name_map, result, exec_opts
    )

Source from the content-addressed store, hash-verified

4541 return s
4542
4543 def _fetch_multi_indexes(
4544 self, connection, owner, names, schema, name_map, result, exec_opts
4545 ):
4546 class="st">"""Execute the unified indexes queries for one catalog pass.
4547
4548 Runs two Core sys.* selects (index metadata + index columns),
4549 grouped by table. Used for both the main-DB pass and the
4550 tempdb pass (with ``schema_translate_map={class="st">"sys": class="st">"tempdb.sys"}``
4551 applied).
4552 class="st">"""
4553 meta_q = self._indexes_metadata_select()
4554
4555 rp = connection.execute(
4556 meta_q,
4557 {class="st">"owner": owner, class="st">"filter_names": names},
4558 execution_options=exec_opts,
4559 )
4560
4561 class="cm"># {table_name: {index_id: index_dict}}
4562 indexes_by_table = {}
4563 for row in rp.mappings():
4564 tname = name_map(row[class="st">"table_name"])
4565 if tname not in indexes_by_table:
4566 indexes_by_table[tname] = {}
4567
4568 current = {
4569 class="st">"name": row[class="st">"name"],
4570 class="st">"unique": row[class="st">"is_unique"] == 1,
4571 class="st">"column_names": [],
4572 class="st">"dialect_options": {class="st">"mssql_include": []},
4573 }
4574 do = current[class="st">"dialect_options"]
4575 index_type = row[class="st">"type"]
4576 if index_type in {1, 2}:
4577 do[class="st">"mssql_clustered"] = index_type == 1
4578 if index_type in {5, 6}:
4579 do[class="st">"mssql_clustered"] = index_type == 5
4580 do[class="st">"mssql_columnstore"] = True
4581 if row[class="st">"filter_definition"] is not None:
4582 do[class="st">"mssql_where"] = row[class="st">"filter_definition"]
4583
4584 indexes_by_table[tname][row[class="st">"index_id"]] = current
4585
4586 cols_q = self._indexes_columns_select()
4587
4588 rp2 = connection.execute(
4589 cols_q,
4590 {class="st">"owner": owner, class="st">"filter_names": names},
4591 execution_options=exec_opts,
4592 )
4593
4594 for row in rp2.mappings():
4595 tname = name_map(row[class="st">"table_name"])
4596 idx_id = row[class="st">"index_id"]
4597 if tname not in indexes_by_table:
4598 continue
4599 if idx_id not in indexes_by_table[tname]:
4600 continue

Callers 2

get_multi_indexesMethod · 0.95

Calls 9

indexesMethod · 0.80
executeMethod · 0.45
mappingsMethod · 0.45
getMethod · 0.45
appendMethod · 0.45
itemsMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected