Z
Z
zhaar2019-09-25 11:28:34
SQL query optimization
zhaar, 2019-09-25 11:28:34

What index to create for the table?

There is a plate that contains information about stores - who they are subordinate to, in what region they are located, where they are stored, etc. The list of columns is:
[DivisionNodeName] varchar(100)
,[DSMid] int non-unique
,[DSMname]
,[ TSMNodeName]
,[TSMid] int non-unique
,[TSMname]
,[SVNodeName]
,[SVid] int non-unique
,[SVname]
,[TPNodeName]
,[TPid] int non-unique
,[TPname]
,[TTfid] int, unique
,[TTexid]
,[TTname]
,[TTowner] int
Actually the question is where and what indexes to add for those fields that I marked as data type.
Do the TTfid field exactly (unique, clustered?), and this figure is partially related to the next field. The point code starts with the server number from the TTowner column, i.e. 20000001 on server 2, 30000435 on server 3, and so on.
Now the index is only on it:
CREATE CLUSTERED INDEX [IX_ttfid] ON [dbo].[DMS_RU_TerritoryHierarchy]
([TTfid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
The TTowner field contains the server, does it make sense to merge with the past? Because this should make it easier to find pages, what index to do from it? If so, which one should you set?
dsmid\tsmid\svid are employee codes, they are repeated, is there any point in trying to put an index on them? Something seems to be missing, even if you want to search for them ... though?
region - does it make sense to hang an index there? If so, which one? In fact, this should make it easier to find points that belong to a particular region without affecting the server.
In total, there are about 400k rows in the table (a little, yes), before writing, the index is now removed, the table is cleared and the data is loaded again. index is set. And so every day.
Subsequently, this table is accessed by other queries, which, for example, pull up a superior employee for a point for about 30-40 million documents (join goes through the fields: TTfid, TPid and TTowner)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2019-09-25
@tsklab

Minimum: Build a query execution plan. There will be hints about which index to add. If there are no such hints, it means that the optimizer coped with the help of statistics.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question