clustered-index

Removing a Primary Key (Clustered Index) to increase Insert performance

有些话、适合烂在心里 提交于 2019-12-23 10:47:09
问题 We've been experiencing SQL timeouts and have identified that bottleneck to be an audit table - all tables in our system contain insert, update and delete triggers which cause a new audit record. This means that the audit table is the largest and busiest table in the system. Yet data only goes in, and never comes out (under this system) so no select performance is required. Running a select top 10 returns recently insert records rather than the 'first' records. order by works, of course, but

How to Query to Find out if a Table has a CLUSTERED Primary Key

ぐ巨炮叔叔 提交于 2019-12-23 10:07:30
问题 I found this question, but it doesn't appear to answer the question... SQL Server - How to find if clustered index exists How can I write an IF T-SQL statement to say: IF NOT ([TableName] has a CLUSTERED PK) ALTER TABLE to add the CLUSTERED PK 回答1: Try this IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID('dbo.MdsInventar') AND index_id = 1 AND is_primary_key = 1) ...... The clustered index always has index_id = 1. Of course - if you check like this (with the is_primary

MySQL compound index not being used

試著忘記壹切 提交于 2019-12-23 09:13:50
问题 I have a large table from which I must select large amounts of rows. The table stores call detail records (CDR's). Example: +-------------+--------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------------------+----------------+ | id | int(45) | NO | PRI | NULL | auto_increment | | calldate | datetime | NO | MUL | 0000-00-00 00:00:00 | | | accountcode | varchar(100) | NO | | | | |

SQL Server - Clustered index design for dictionary

爷,独闯天下 提交于 2019-12-22 11:32:56
问题 Would like some advice from this. I got a table where I want to keep track of an object and a list of keys related to the object. Example: OBJECTID ITEMTYPE ITEMKEY -------- -------- ------- 1 1 THE 1 1 BROWN 1 2 APPLE 1 3 ORANGE 2 2 WINDOW Both OBJECTID and ITEMKEY have high selectivity (i.e. the OBJECTID and ITEMKEY are very varied). My access are two ways: By OBJECTID: Each time an object changes, the list of key changes so a key is needed based on OBJECTID. Changes happen frequently. By

does Firebird defrag? If so, like a clustered index?

左心房为你撑大大i 提交于 2019-12-22 08:48:17
问题 I've seen a few (literally, only a few) links and nothing in the documentation that talks about clustering with Firebird, that it can be done. Then, I shot for the moon on this question CLUSTER command for Firebird?, but answerer told me that Firebird doesn't even have clustered indexes at all, so now I'm really confused. Does Firebird physically order data at all? If so, can it be ordered by any key, not just primary, and can the clustering/defragging be turned on and off so that it only

Clustered index on temp table

痴心易碎 提交于 2019-12-22 08:47:28
问题 I'm trying to optimize a procedure that has code like the following: CREATE TABLE #t1 (c1 int, c2 varchar(20), c3(varchar(50)...) CREATE CLUSTERED INDEX ix_t1 ON #t1(c3) ON [PRIMARY] I wanted to improve that by moving the CLUSTERED index into the table declaration (more caching friendly), but c3 is not unique so this doesn't work: CREATE TABLE #t1 (c1 int, c2 varchar(20), c3 varchar(50)..., UNIQUE CLUSTERED (c3)) Is there a way to declare a clustered that is not unique in the temp table

B-trees, databases, sequential vs. random inserts, and speed. Random is winning

拟墨画扇 提交于 2019-12-22 05:07:58
问题 EDIT @Remus corrected my test pattern. You can see the corrected version on his answer below. I took the suggestion of replacing the INT with DECIMAL(29,0) and the results were: Decimal: 2133 GUID: 1836 Random inserts are still winning, even with a fractionally bigger row. Despite explanations that indicate random inserts are slower than sequential ones, these benchmarks show they are apparently faster. The explanations I'm getting aren't agreeing with the benchmarks. Therefore, my question

B-trees, databases, sequential vs. random inserts, and speed. Random is winning

折月煮酒 提交于 2019-12-22 05:07:15
问题 EDIT @Remus corrected my test pattern. You can see the corrected version on his answer below. I took the suggestion of replacing the INT with DECIMAL(29,0) and the results were: Decimal: 2133 GUID: 1836 Random inserts are still winning, even with a fractionally bigger row. Despite explanations that indicate random inserts are slower than sequential ones, these benchmarks show they are apparently faster. The explanations I'm getting aren't agreeing with the benchmarks. Therefore, my question

Is Unique key Clustered or Non-Clustered Index in SQL Server?

流过昼夜 提交于 2019-12-21 02:59:11
问题 I am new to SQL Server and while learning about clustered index, I got confused! Is unique key clustered or a non-clustered index? Unique key holds only unique values in the column including null, so according to this concept, unique key should be a clustered index, right? But when I went through this article I got confused MSDN When you create a UNIQUE constraint, a unique nonclustered index is created to enforce a UNIQUE constraint by default. You can specify a unique clustered index if a

Changing newid() to newsequentialid() on an existing table

試著忘記壹切 提交于 2019-12-20 10:56:18
问题 At the moment we have a number of tables that are using newid() on the primary key. This is causing large amounts of fragmentation. So I would like to change the column to use newsequentialid() instead. I imagine that the existing data will remain quite fragmented but the new data will be less fragmented. This would imply that I should perhaps wait some time before changing the PK index from non-clustered to clustered. My question is, does anyone have experience doing this? Is there anything