New answers tagged

0

You can define a second UNIQUE index on the table that contains the appropriate INCLUDE clause, then define new foreign keys referencing this index. If you use the CONCURRENTLY clause of CREATE INDEX, that shouldn't be disruptive. Then you can delete the original primary key and all dependent foreign keys using DROP INDEX ... CASCADE. You can then make ...


2

gin index type is about 10 times smaller and about 3 times as performant as the default btree index (the performance was tested using SELECT queries). and: it's 30GB for btree and 3GB for gin Yes, that speaks heavily in favor of the GIN index. OTOH, this: repeated about 100 times on average. and this: I think I won't ever UPDATE the other_id ...


3

This seems like a rather esoteric thing, which is probably why it doesn't get recommended all that much. I do recommend it when the issue comes up, which just isn't all that often. The size of one index is unlikely to be all that meaningful in the context of an entire database, so making it smaller usually isn't worth worrying about a great deal. I don't ...


3

If auto update statistics is not enough for your DB, try a couple of things: Manually update statistics - recommend Ola Hallengren's scripts that can be configured to maintain indexes and/ or statistics as required. Test different parameters (all/ indexes only/ sample rate etc) and test running daily/ weekly/ at start of proc and the like, and see what ...


3

Column statistics are created automatically as needed by SQL Server when the AUTO_CREATE_STATISTICS database option is ON and also by an explict CREATE STATISTICS statement. With the AUTO_CREATE_STATISTICS database option, the query optimizer will create single column stats during query compilation as needed on columns specified in query predicates when a ...


2

The extension you need is btree_gin and not pg_trgm. I would say that the biggest drawback is that GIN indexes are slower to update than B-tree indexes (which is why the fastupdate option was invented). If that is fine with you because you have few data modifications, and query speed is more important, use the GIN index (but then I would recommend ...


2

SQL Server optimiser uses statistics to generate execution plans. The more accurate statistics the better plans it can potentially generate. By default statistics automatically updated only if more than 20% of the records have been changed. What does it mean in practice? Let's say you have a table with 10 months of data and statistics was just recalculated. ...


0

Try using $hint in your query to enforce your optimizer to use this specific index for the query and post the output. Thank you! -Anban


0

It's not possible to achieve without using temp table as the DMVs/DMFs that we are using are database scoped and requirement is server scoped, and i don't see any difficulties or complication using temp table as follows: Declare @Tbl table (ServerName varchar(128), DBName varchar(128), SchemaName varchar(128), TableName varchar (100), IndexName varchar (100)...


-1

I can think of one additional benefit but it is mostly due to limitations of JPA, Spring and MySQL. MySQL defaults to case insensitive unless you use MySQL specific constructs like BINARY in columnDefinition or utf8mb4_bin thus causing portability / sorting issues. In which case the workaround was to create an index column containing the SHA-1 which will ...


1

You can use dynamic SQL with a do statement that iterates over the tables in a schema: do $$ declare l_statement text; l_rec record; begin for l_rec in select y from x loop l_statement := format('create index on %I (z)', l_rec.y); execute l_statement; end loop; end; $$ Postgres will automatically generate a name for the new ...


0

How did you determine that the table(s) has no unique indexes? Primary keys and unique constraints are implemented via unique indexes (unless the are informational constraints, i.e. NOT ENFORCED). Try: SELECT INDSCHEMA, INDNAME FROM SYSCAT.INDEXES WHERE UNIQUERULE IN ('U','P') AND TABSCHEMA = '...' AND TABNAME = '...'


0

https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.5.0/com.ibm.db2.luw.admin.dbobj.doc/doc/c0061097.html It is important to understand that there is no significant difference between a primary key or unique key constraint and a unique index. To implement the concept of primary and unique key constraints, the database manager uses a combination of a ...


2

Just use the sys.columns table: SELECT name, is_sparse, is_column_set FROM sys.columns Column sets are: Tables that use sparse columns can designate a column set to return all sparse columns in the table. A column set is an untyped XML representation that combines all the sparse columns of a table into a structured output. A column set is like a ...


0

That would require significant changes, and I doubt it can be done easily. See these excerpts from src/include/access/itup.h: /* * Index tuple header structure * * All index tuples start with IndexTupleData. If the HasNulls bit is set, * this is followed by an IndexAttributeBitMapData. The index attribute * values follow, beginning at a MAXALIGN ...


0

if ID and ID2 columns are key columns then you need to worry about that faulty Update Statement. Agree, those values aren't being changed but it create very expensive Query Plan. In Fact you should Compare the query Plan with and without mt.col1 = s.col1 , mt.col2 = s.col2 in Update your Self. Begin Tran UPDATE mt SET mt.col1 = s.col1 , ...


1

SQL server may choose to perform an in-place update or an insert and a delete depending on many factors and you shouldn’t worry about it. Since the keys are not being updated I would leave them out of the SET clause to help the optimizer make the best decision. If you are using SQL Server 2008 or later, look at the MERGE statement which can replace both ...


9

I'd run DBCC UPDATEUSAGE against the table as a first step, since the symptoms show inconsistent space usage. DBCC UPDATEUSAGE corrects the rows, used pages, reserved pages, leaf pages and data page counts for each partition in a table or index. If there are no inaccuracies in the system tables, DBCC UPDATEUSAGE returns no data. If inaccuracies are found ...


-3

I've encountered this problem before on production boxes, what you need to do is rebuild tables and indexes for each table (in that order). Here's the query I use to keep tables in check. It will help you determine which tables need to be rebuilt, and create the SQL queries you need to run. This query is limited to those with higher than 1MB unused space ...


0

One of the columns is a LOB of type image, and it's storing files that range in size from a few KB to several hundred MB You could be experiencing internal fragmentation. What is the page fragmentation for this table? And is the fragmentation for the in-row different from the off-row pages? You say you have files that are a few KB. SQL Server stores ...


0

Give this a try (and let us know if it helps): SELECT p.*, ft.relevance FROM ( SELECT id, MATCH (brand, name, variation) AGAINST('something' IN BOOLEAN MODE) AS relevance FROM Product WHERE MATCH (brand, name, variation) AGAINST('something' IN BOOLEAN MODE) ) AS ft JOIN Product AS p USING(id)...


2

It's important to know what sort of queries you are running. Are they mostly based on the time of the record, or something other field? That will inform what sort of approach you should take here. Maybe your indexes should actually be multi-indexes for example. What's your EXPLAIN statement say for your queries? That's really one of the best ways to see ...


0

Suggestion for your my.cnf [mysqld] section innodb_lru_scan_depth=100 # from 1024 to reduce the 'amount of work per second' To conserve about 90% of CPU cycles used for this function, per https://dev.mysql.com/doc/refman/5.6/en/innodb-parameters.html#sysvar_innodb_lru_scan_depth when you have innodb_buffer_pool_instances=32.


0

In Cost base Optimization,Optimizer find best possible execution on given time which is cost effective. When we check the index size of each index in this table, SELECT i.name AS IndexName, SUM(page_count * 8) AS IndexSizeKB FROM sys.dm_db_index_physical_stats( db_id(), object_id('Sales.Customer'), NULL, NULL, 'DETAILED') AS s JOIN sys.indexes AS i ON s....


1

I fixed it by adding the feed_id field to the ORDER BY clause like that: mysql> EXPLAIN SELECT a.id FROM articles a WHERE a.feed_id IN (6826,6827) AND a.date < 1564469723.424363 ORDER BY a.date DESC, a.feed_id DESC LIMIT 20; +----+-------------+-------+-------+-------------------+--------------+---------+------+------+----------------------------------...


4

You use a nonequality predicate so your "seek" operations are in fact scans which just start from some value (not from "first") and then go to the end of the clustered index leaf level. In the other hand you return only one column which is the clustered index key so using any of indexes won't get any key lookup operations. The optimizer has to estimate what ...


-1

The optimizer uses whatever it thinks is fastest; a lot of times what I'd expect it to do, it doesn't. It's not just based on row %; it's based on lots of factors like the statistics it has, indexes, the table columns and query itself. Uses that to create cost and threshold estimates, although number of rows does come into play. I'd guess it scanned the ...


4

Indices are bound to fragment in course of usage (time). What matters is if it is affecting the performance. Usually we do not worry about of indices with page_count < 500. (We as in, my team)However,there is not hard and fast rule for a particular page_count.In my previous shop we had set the limit in our Ola script for 1000 page count. But yes with ...


3

Main difference between your Test server and Live server is Concurrency. You haven't done Concurrency Test in your Test server. Concurrency is one of the main reason for Live Site to be slow. What code is written in Front end application like what you have written in connection string . Like connection pool,whether connection is properly close after ...


11

Based on the data that you have provided - there are 67 total pages. Index fragmentation for such a small table would not affect the performance. I would not worry about index fragmentation for the table that you have mentioned. You should update your table statistics so that sql server can generate better query plan. I would start my troubleshooting by ...


1

You cannot. These are different operations, and only one of them is supported by the index. If you were to swap the order of the arguments as well as the operator itself, then it would be the same operation and the index would still support it. Although it might be possible that you could modify the source code of pg_trgm to support this other operation. ...


-3

The only time I've been unable to shrink a DB and reclaim space is because you cannot shrink a DB beyond the initial size of the DB when it was created. So for example, if your DB is a copy of the production DB and you first created the DB at 525GB, sql server will not allow you to shrink the size below 525GB no matter how much data you delete from the DB. ...


2

The index does not match exactly what already exists. The Clustered index (the primary key) contains all the other data related to the table. But the nonclustered index (NCI) contains just the primary key. The resulting NCI is much narrower than the clustered index. Having a non-clustered index on just the primary key has a few benefits that may be ...


0

Since you said that , ,INSERTs are relatively rare (at most dozens of times per day, but typically much less than that), reads are very frequent (essentially on every web request to my application).INSERT performance doesn't matter too much, but I'd like to avoid horrible index fragmentation if at all possible Alter your Table to add RowNumber ...


5

You can't compare performance of: WHERE color_code in ('red','green') and sale_date = '1970' with: WHERE color_code = 'red' or color_code = 'green' and sale_date = '1970' because they are not logically equivalent (will return different results). A trivial example: with T (color_code, sale_date) as ( values ('red', '1970'), ('green','1969') ) ...


1

I think the difference in timing you see is simply a caching effect, based on which query you ran first. It is probably not a real difference caused by how you specify the query (Although as Lennart described, your queries are not really equivalent as you are missing parentheses around the OR part--although all your rows seem to meet sale_date = '1970' ...


9

With a trivial SELECT COUNT(*) FROM dbo.YourTable; query on a disk-based table, SQL server counts rows by scanning either the heap or leaf nodes of an index. The cost-based SQL Server optimizer chooses the narrowest one available in order to minimize the number of pages scanned. This example shows the behavior with an index scan. CREATE TABLE dbo.YourTable(...


1

If the only reason for the index is the above query, then a partial index would better: CREATE INDEX my_index ON my_table(time desc, service_name) WHERE status='ok'; VACUUM ANALYZE my_table; may help too. The query plan depends on actual data in the table. In a table with few or zero records a seq scan is cheaper. If you really dont want the seq scan (...


2

How fast do you expect this to be? It is taking about the amount of time I would expect (a little slower, but that is probably your hardware). The query may be simple to specify, but it handles a large amount of data. Most of the time of the nested loop is taken up by waiting for its first child (the hash join) to returns its results. The nested loop ...


3

I think, from performance perspective, it will be very close. But some thoughts: One column indexes do not store NULL values. So individual indexes will be smaller. Composite index (item_type, item ) size will be bigger than sum of individual indexes. In extreme cases even the height of indexes may differ. Two of three individual indexes will be unique, ...


2

I don't speak Oracle, but I can't see any advantages, logical or performance-wise - with your first scenario. As @brian-leach suggests in his comment, you should enforce the mutual-exclusivity, but that will slow down inserts. Using this scenario, not only would I be worried about adding item_d to the collection, what happens when item_x gets an additional ...


-3

Is the database in full recovery mode? If so, when you perform a shrink, it's logging all of the changes and won't shrink it the way you're expecting. Depending on your hours of operation, you could take a backup, switch to bulk-shipping recovery mode and then run the shrink on the data file. After that, you'd want to run index scripts to repair/rebuild ...


1

As ever, it all depends on how you're going to access the data. If you only ever query the table by item_1, then indexing the other two would be a waste of time. If you most commonly query the table by item_1 and sometimes by item_2 as well then a composite index on item_1 and item_2 might be a good idea. Your database can use the composite index for ...


-1

The composite index would be better than three separate indexes because it would be able to use it for all three columns but you will want to pay attention to the order of the columns because it DOES matter. Could you not test and compare in dev/test environment? See quote below. RedGate: "For composite indexes, take into consideration the order of the ...


2

Clustered Index : Help to store table data on on pages in sorted order according to key column. So you can say it's sorted table (clustered table). Non-Clustered Index : Store key value on IAM (Index Allocation Map) pages along with row address, like page id and row offset, that helps query to find rows on data pages. So you can say, after creating ...


2

So with the updated index the First Update works fine,it uses the updated Non Clustered Index , but for second update it ask me to create a non clustered index on column3. The updates will always work fine. Is this an update query you run very frequently? Because in general (extra) non clustered indexes slow down inserts. All your data is in the Clustered ...


Top 50 recent answers are included