New answers tagged

1

The actual data in a page is not necessarily in any particular order. The logical order of data in any index 8k page is determined in the row offset array. https://www.sqlservercentral.com/blogs/does-a-clustered-index-really-physically-store-the-rows-in-key-order


0

Plus to what was given above. I'll give you my index suggestion for your specific query: --Added to show you how you use the SELECT columns in the IX INCLUDE section. SELECT t1.col1, t1.col2 , t2.colA, t2.colB FROM t1 LEFT JOIN t2 ON (t1.id = t2.id AND t2.userid = @userid) WHERE t1.enabled = 1 AND t1.startDate <= '2021-02-26 19:03:04.437' AND ...


1

Indexes on foreign keys are prescriptive. IE they are not there to optimize SELECT queries, they are there to prevent excessive locking and scanning when updating the primary key table. So an exception to the general rule is fine for foregn keys to tables which are essentially static (ie updated, if at all, during maintence windows), supporting the index ...


5

Short answer No. Long answer No, and adding the index could be detrimental to performance. Something that factors heavily into whether or not a secondary/non-clustered index is even used is how selective it is (and the searches you are trying to perform are). Y/N has two values - it's ability to be selective is going to depend on the proportion of Y to N. ...


1

Placing the foreign key will cause internally a key lookup into the one page that will be required by your Yes/No table. This will be trivial for the most part and will not consume much cpu, but the code path of a simple check constraint will likely be faster and wont involve any locks or latches. For the scenario you have where the values of the column is ...


0

If you will delete (or update the id) records from small table index helps. If you dont index big table delete will lock and scan the whole table. If there is an index delete statement will also lock the table but scan the index which is cheaper.


1

May not necessarily apply to your case but I think important to know for whomever it could apply to, and relevant. If any of those tables are larger in size (100s of millions of rows / 100s of GB in size) and the index you're considering to DROP is the clustered index, bare in mind this operation will likely take substantially longer than dropping a ...


5

If you are unsure if you have a periodic report or job running that might use an index you would be well advised to disable the index rather than dropping it as then you have the definition in situ should you discover that it was after all required. ALTER INDEX IX_Employee_ManagerID ON HumanResources.Employee DISABLE; and ALTER INDEX IX_Employee_ManagerID ...


3

In addition to unique indexes, indexes supporting foreign keys should normally be retained even if they are infrequently used.


8

If there was a clever person who decided to use index hints in their application's queries, dropping said index will cause the query to fail outright if/when it runs. Something like a quarter or year-end report might not be showing any index usage due to its infrequency of execution depending on how often the system is restarted.


0

You could make it a bit faster by replacing the TEXT array with an INT array referencing a separate table which would store the tag texts along with an integer key. Now, here's an idea: You're always ordering by "created_at DESC" with a LIMIT clause. Or you have a date range, because no-one is really interested in having a million search results ...


4

Updates is the one you IMO you should weigh the positive aspects of the index (seek and scan) against. With few updates, then the the overhead is marginal. Unless you consider diskspace, but I assume you are after "what makes things go slower" as opposed to "what uses storage". Note that if an index hasn't been touched since startup, you ...


2

If the index is not enforcing uniqueness, it is only there to (potentially) assist in read access. I'd just caution against dropping indexes that might be used for quarter end/year end reporting jobs that have been created to avoid locking tables for extended periods of time. You'll have to use some judgment and knowledge of the tables to determine that or ...


1

Yes, if you have values that increase monotonically, the B-tree index will end up densely packed. Subsequent updates and deletes will still lead to fragmentation, but that is normal.


1

With B-Tree indexes, more importantly is the cardinality of the data you're indexing. The more unique the data is in the index, generally the better candidate it is for a B-Tree index because it'll result in a much more full tree with many branches and leaves. A very non-unique field, like a boolean based field, will always only have two distinct values, and ...


5

To go a bit more into details, the plan isn't flushed when the index is dropped. See repro below. The plan stay in cache, but it is now invalid. Next time that plan is up for usage, SQL Server check whether it is valid. If for instance a schema change was made (as in dropping an index), it isn't valid. So a new plan will be generated. Dropping the plan when ...


5

Welcome to DBA.StackExchange, and interesting question!...one I've never thought of before. I had to double check myself on what I thought the process was, so I think this StackOverflow Answer should be what you're looking for. Specifically the first statement of the answer: Dropping/Rebuilding an Index will result in invalidation of any cached execution ...


0

Alright... let's have some test data. CREATE UNLOGGED TABLE foo( id INTEGER PRIMARY KEY, doneCleanup BOOL NOT NULL, alertedUser BOOL NOT NULL, doneCleanupTimestamp TIMESTAMP NOT NULL, initialTimestamp TIMESTAMP NOT NULL); INSERT INTO foo SELECT n, random()<0.9, random()<0.9, '2020-01-01'::TIMESTAMP+'1 SECOND'::INTERVAL*(n + random()*1000), '2020-01-...


0

This are the quick steps to fix the corruption: Step 1 Using telnet, ssh, or a local machine, connect to the mySql server and log into the mySql command-line tool. This can be done with mysql -p. Step 2 Use the CHECK TABLE tablename FOR UPGRADE command to verify the table needs to be repaired. Step 3 Exit the mysql command-line tool by typing x and pressing ...


0

The values in filtered column in both execution plans look pretty off target. Maybe it would help to disable condition_fanout_filter optimizer switch in the session executing these multi-join queries (see more about condition filtering). Why would the query planner suddenly decided use a different execution plan on a query that has been in use for a while? ...


1

Check for table and index sizes. Your first index uses 3 columns and its size is probably very big so optimizer chooses full table scan. Index scan vs full table scan also depends on random_page_cost (default value 4). If random_page_cost is set lower optimizer will chose index scans over full table scans.


2

will removing this index impact the check constraint performance? No, it will not. Check constraints only operate on the columns of a single row, not on multiple rows. So it is completely unaffected by the existence (or absence) of an index.


4

An index can only support operators that belong to its operator class. SELECT ao.amoplefttype::regtype, op.oprname, ao.amoprighttype::regtype FROM pg_opfamily AS of JOIN pg_am AS am ON of.opfmethod = am.oid JOIN pg_amop AS ao ON of.oid = ao.amopfamily JOIN pg_operator AS op ON ao.amopopr = op.oid WHERE am.amname = 'btree' AND ao....


1

Simply put, as the table (or index) grows, the performance approaches a minimum of one disk hit per lookup. This is because UUIDs (other than a version 1 UUID with the bits suitably shuffled) are effectively "random". That is whatever is in the buffer_pool cache is approaches being useless for the next lookup. You seem to have 3 such indexes; this ...


2

"billions of records" and id int(10) unsigned NOT NULL AUTO_INCREMENT -- Beware! That will top out at about 4 billion. To speed up the inserts, see if you can batch them something liek this: insert into `productcatalog` (`id`, `SerialNumber`, `BasePrice`, `BatchCode`, `Type`, `ItemCode`, `ArrivalDate`, `InsertTimestamp`, `BrandID`, `...


2

A compound index can also support queries that compare columns that are at the beginning of the indexed values (but aren't all). So an index on (field1, field2) (which is implicitly created for a primary key) would also support queries that compare only field1. But it cannot support queries that only compare columns of its end (but aren't all). So (field1, ...


0

Partitioning (at least from the perspective of SQL Server, but probably applies to most RDBMS) is not meant to be a tool for improving DQL query performance. E.g. your bread and butter SELECT statements won't see any impactful performance gains from partitioning, as you mentioned because of the Big O of B-Tree indexing. Rather it's meant to improve the ...


0

I find this command helps to show index progress: db.currentOp().inprog.map(a => a.msg) [ undefined, undefined, undefined, undefined, undefined, undefined, "Index Build: scanning collection Index Build: scanning collection: 16448156/54469342 30%", undefined, undefined ]


0

Not directly an answer, but related: there are functions to reset the statistics whenever you want. From the manual: pg_stat_reset() resets all statistics counters for the current database to zero (requires superuser privileges by default, but EXECUTE for this function can be granted to others.) pg_stat_reset_single_table_counters(oid) resets statistics for ...


1

I think you answered your own question, SQL Server will only use an index for sorting if the columns are in the index definition keys (the sorted part) not in the included column list (as then the values are not sorted). If your users can choose one of multiple sorts you will need multiple supporting indexes, and some carefully written queries.


0

The planner lacks much insight into the inner workings of GiST indexes, which often leads to poor cost estimates for them. However, I don't see the point of the GiST index in the first place. Every column in it is using WITH =, so why not just use a unique constraint?


0

As the other answers stated, the data type has no influence on the query speed, but on the readability of the query and its results. Your execution plan shows that the query is I/O bound. You are reading a lot of data (219478 * 8kB), because you need a lot of rows, and the rows are in different table blocks. First, make sure that your index is defined the ...


1

I'm going to answer the spirit of the question, which is "would timestampz fix my query performance?" Now that you've provided your index definitions, I can say with certainty you have your indexes set up wrong for the type of search you are conducting. Right now your indexes are ordered by timestamp. This is useful for finding ALL rows at a point ...


4

To answer your basic question: No. timestamptz is stored as 64 bit integer quantity internally (same as int8). An index on it performs identically to one on a bigint (int8) column - when used correctly. Related: Ignoring time zones altogether in Rails and PostgreSQL If in doubt, go with timestamptz. It's built for the purpose. The only argument in favor ...


Top 50 recent answers are included