Questions tagged [database-indexes]

An index contains keys built from one or more columns in the table, or view, and pointers that map to the storage location of the specified data.

An index contains keys built from one or more columns in the table, or view, and pointers that map to the storage location of the specified data.

References:

Top Questions related to Database Indexing

571 questions
5
votes
3 answers

Does the ORDER BY optimization takes effect in the following SELECT statement?

I have a SELECT statement which I would like to optimize. The mysql - order by optimization says that in some cases the index cannot be used to optimize the ORDER BY. Specifically the point: You use ORDER BY on nonconsecutive parts of a key …
Christian Ammer
  • 7,464
  • 6
  • 51
  • 108
5
votes
1 answer

Rails -- database index necessary for :id attribute?

So as I was following the Ruby on Rails Tutorial by Michael Hartl I noticed that in the users table we added a unique index for the :email attribute to improve the efficiency of the find method so it doesn't search row by row. So far we have been…
Kvass
  • 8,294
  • 12
  • 65
  • 108
5
votes
2 answers

Index on expression (JSON_EXTRACT) not used

I'm having trouble getting SQLite to index an expression. Specifically, I want to create an index on a particular property in a JSON object. CREATE TABLE test (tags JSON); INSERT INTO test VALUES(JSON_OBJECT('someKey', 'someValue')); CREATE INDEX…
Brad
  • 159,648
  • 54
  • 349
  • 530
5
votes
1 answer

PostgreSQL 11 goes for parallel seq scan on partitioned table where index should be enough

The problem is I keep getting seq scan on a rather simple query for a very trivial setup. What am I doing wrong? Postgres 11 on Windows Server 2016 Config changes done: constraint_exclusion = partition A single table partitioned to 200 subtables,…
5
votes
1 answer

Why PostgreSQL doesn't use trigram index

I have created a trigram index in order do execute a query with a 'like %text%' condition, but PostgreSQL 9.6 doesn't use the index to perform the query. CREATE EXTENSION pg_trgm; CREATE INDEX tb_estabelecimento_index08 ON tb_estabelecimento …
Rodrigo
  • 2,313
  • 2
  • 15
  • 23
5
votes
2 answers

Determine status of an index in mysql

I created a new index on a table with 35million records and its been running for nearly 1 day now. Previously when I created indexes it took 20 minutes, there columns were however floats. The new idnex is on a varchar(45) I used the processlist…
Steve
  • 21,163
  • 21
  • 69
  • 92
5
votes
1 answer

Putting an index on a date field in MySQL

Is there going to be any real benefit to me putting indexes onto date fields that are going to be mainly used in queries using stuff like. dateField < 'var' And 'var' BETWEEN dateField1 AND dateField2 The searches get done a lot but I am never…
Toby
  • 8,483
  • 13
  • 45
  • 68
5
votes
5 answers

Unique constraint in MySQL

Is a unique constraint an index by default? If not, does a unique constraint has the same performance results as an indexed column when using it in the SELECT ... WHERE clause? Thanks
4
votes
2 answers

MySQL Error: Index column size too large. The maximum column size is 767 bytes

I've unsuccessfully been through the AWS forum and Stack Overflow trying to find a solution to the following error: Index column size too large. The maximum column size is 767 bytes I am running a WordPress website with 1.5M records in the postmeta…
Zac
  • 118
  • 1
  • 6
4
votes
1 answer

Given a query, how do you know which indices to add?

Is there some tool that does this? You give it a SQL query and it gives suggestions. For example, I'm trying to optimize the following query: Load (383.2ms) SELECT COUNT(*) as plays, p.chosen_race as race, p.won as won, r.game_type as type FROM…
randomguy
  • 12,042
  • 16
  • 71
  • 101
4
votes
2 answers

Is it possible to do usual atomic INSERT operation but update Indexes asynchronously?

indexes make read fast but write slower. But why can't you have single writes and have db add indexes asynchronously with time, also cache in the INSERT until it's indexed? Is there any database like that?
Muhammad Umer
  • 17,263
  • 19
  • 97
  • 168
4
votes
2 answers

Cannot drop index in postgres because it does not exist

In a postgres database, I have a unique constraint and two unique indexes created for the same. I deleted the constraint using the query below: alter table my_schema.users drop constraint users_dept_uk It has dropped the constraint and one index…
newbie
  • 1,282
  • 3
  • 20
  • 43
4
votes
1 answer

How long are stats in PostgreSQL's pg_stat_all_indexes table stored?

I use PostgreSQL 11.1 and I'm trying to gather information from pg_stat_all_indexes table about indexes usage to determine whether a particular index can be removed or not - according to Index size/usage statistics section in…
4
votes
3 answers

How to get the list of column names for all indexes on a table in PostgreSQL?

I have this query to get the list of indexes on a table: SELECT ns.nspname as schema_name, tab.relname as table_name, cls.relname as index_name, am.amname as index_type, idx.indisprimary as is_primary, idx.indisunique as…
Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447
4
votes
3 answers

Why is only reading faster in an indexed table and not writing?

The data structure used for indexing in a DB table is B-Tree (default, out of B-Tree, R-Tree, Hash). Since look-ups, deletions, and insertions can all be done in logarithmic time in a B-Tree, then why is only reading from an indexed table is faster…
Jack
  • 165
  • 2
  • 10