Postgres query optimization (forcing an index scan)

For testing purposes you can force the use of the index by “disabling” sequential scans – best in your current session only: SET enable_seqscan = OFF; Do not use this on a productive server. Details in the manual here. I quoted “disabling”, because you cannot actually disable sequential table scans. But any other available option … Read more

Meaning of “Select tables optimized away” in MySQL Explain plan

From the MySQL documentation: The query contained only aggregate functions (MIN(), MAX()) that were all resolved using an index, or COUNT(*) for MyISAM, and no GROUP BY clause. The optimizer determined that only one row should be returned. Basically this means your query uses data that is directly available to MySQL and the query will … Read more

MySQL explain Query understanding

Using temporary means that MySQL need to use some temporary tables for storing intermediate data calculated when executing your query. Using filesort is a sorting algorithm where MySQL isn’t able to use an index for sorting and therefore can’t do the complete sort in memory. Instead it breaks the sort into smaller chunks and then … Read more

How to find out what is locking my tables?

Take a look at the following system stored procedures, which you can run in SQLServer Management Studio (SSMS): sp_who sp_lock Also, in SSMS, you can view locks and processes in different ways: Different versions of SSMS put the activity monitor in different places. For example, SSMS 2008 and 2012 have it in the context menu … Read more

Improving OFFSET performance in PostgreSQL

You might want a computed index. Let’s create a table: create table sales(day date, amount real); And fill it with some random stuff: insert into sales select current_date + s.a as day, random()*100 as amount from generate_series(1,20); Index it by day, nothing special here: create index sales_by_day on sales(day); Create a row position function. There … Read more

What is the difference between Seq Scan and Bitmap heap scan in postgres?

http://www.postgresql.org/docs/8.2/static/using-explain.html Basically, a sequential scan is going to the actual rows, and start reading from row 1, and continue until the query is satisfied (this may not be the entire table, e.g., in the case of limit) Bitmap heap scan means that PostgreSQL has found a small subset of rows to fetch (e.g., from an … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)