Skip to main content

20 posts tagged with "optimize"

View All Tags

Order by Random Optimization

· 5 min read
PawSQL Team
Optimize your SQL Queries by Clicks!

Problem

Functionrand(MySQL) or random(PostgreSQL) returns a random floating-point value in the range 0 to 1.0. It is useful to get a random sample of dataset using following query.

select * from orders order by rand() limit 1; 

This works fine if customer table is less than 10,000 rows. But when you have 1,000,000 rows, the overhead for sorting the rows becomes unacceptable. The reason is quiet clear: we sort all rows, but only keep one.

Principles of Database Index Design

· 15 min read
PawSQL Team
Optimize your SQL Queries by Clicks!

Indexes are one of the most important tools for optimizing database performance. However, creating too many indexes or indexing the wrong columns can also have a negative impact on performance. Therefore, it is important to follow certain principles when designing indexes.

Types of Database Index

· 9 min read
PawSQL Team
Optimize your SQL Queries by Clicks!

A database index is a data structure used to speed up database queries. It is similar to the catalog of books and can help quickly locate a certain row or rows in a table. A database index usually consists of a set of index keys (or index fields) whose values are stored in a data structure for fast lookup of specific rows.

Node Type of Explain Tree

· 4 min read
PawSQL Team
Optimize your SQL Queries by Clicks!

PostgreSQL

数据访问

SEQ SCAN: 通过顺序扫描输入记录集来查找相关记录,顺序扫描(与索引扫描不同)执行单个读取操作。 CTE SCAN: 对公共表达式(CTE)查询结果执行顺序扫描。请注意,CTE的结果被计算并临时存储(Materialization)。 INDEX SCAN: 根据索引查找相关记录。索引扫描执行两次读取操作:一次读取索引,另一次从表中读取实际值。

Four Pitfalls of SQL Processing with Null Values

· 10 min read
PawSQL Team
Optimize your SQL Queries by Clicks!

Channel of advanced SQL tuning

Overview

NULL value processing is the most error-prone for database application developers, mainly because we are accustomed to using binary Boolean logic, while the database's processing logic for NULL values is three-valued logic. In fact, the most flawed component in the database optimizers is the logic related to NULL value processing. Even mature database software, such as DB2/Teradata, still has more than 20% of the bugs related NULL processing.

In this article, we analyze the root causes of the NULL value pitfalls, and conclude with a simple and effective examination logic to infer the final result. At the same time, we explain the applicable conditions and solutions for the four common scenarios in daily development work. After reading this article, you will be able to cope with all the scenarios regarding NULL value handling in your daily SQL processing work.