Вход на сайт

Просмотр новости

Найдите то, что Вас интересует

Combinatorial blowups can occur in Name Resolution, too.

Дата публикации: 01-10-2023 18:34:47

Short: There are many places where (any) query optimizer has to take care to avoid combinatorial blowups of memory and/or processing time. But we had a real world query that had a combinatorial blowup at Name Resolution (aka “binding” or “semantic analysis”) phase. Long: The trick is to use nested derived tables (or views) and […]
Combinatorial blowups can occur in Name Resolution, too. appeared first on MariaDB.org


Основное содержимое страницы с новостью.

Skip to content

Short: There are many places where (any) query optimizer has to take care to avoid combinatorial blowups of memory and/or processing time. But we had a real world query that had a combinatorial blowup at Name Resolution (aka “binding” or “semantic analysis”) phase.

Long: The trick is to use nested derived tables (or views) and use the column multiple times.

The example using views. Start from a base table:

create table t1 (
  f1 int,
  f2 int,
  ...
);

Then create a view with columns that refer to the base table multiple times:

create view v1 as
select 
  case 
    when f1 > f2 then f2
    when f1 > f3 then f3
    when s1 > f4 then f4
  end AS f1,
  ...
  case ...  as f2,
  ...
from 
  t1;

Here, v1.f1 has 9 references to columns of t1. Other columns have similar definitions.
Then, create view v2 that uses columns of v1 in a similar way:

create view v2 as
select 
  case 
    when f1 > f2 then f2
    when f1 > f3 then f3
    when s1 > f4 then f4
  end AS f1,
  ...
  case ...  as f2,
  ...
from 
  v1;

v2.f1 has 9 references to v1.f1. Each of those has 9 references to columns of t1, which gives 9*9=81 references to columns of t1.

Repeat this until you reach depth level 8, and now the query takes about 1 minute in MariaDB and MySQL. In PostgreSQL, it is killed due to running out of memory. All the details can be found in MDEV-31130.

In MariaDB (and MySQL), multiple references to the same column are shared, so query processing doesn’t require a combinatorial amount of memory (like it seems to do in PostgreSQL). But condition processing ignores shared references and so does require combinatorial amount of time.

One can imagine fixing this by extending all the code that processes scalar expressions to handle common sub-expressions. But I also imagine it will add a lot of complexity, all just to handle a fairly exotic case, right?

Схожие новости

#Наименование новостиТональностьИнформативностьДата публикации
1Optimizer-related fixes in current batch of stable releases08.1219-11-2023
2Notable optimizer fixes released in February, 202407.8329-02-2024
3ClickHouse Schema Design and Data Modeling05.517-07-2026
4Supercharge your app: MariaDB in-memory tables as a cache09.5201-08-2024
5Interesting Binary Logging Optimization in MariaDB04.8726-05-2025
6Using Linux perf: do we need to pass identifying info as arguments to important functions?05.601-03-2024
7Using temporary tables in MariaDB05.7602-05-2024
8MariaDB has broken the concept of dynamically configurable buffer pools!010.1809-02-2026
9Say the Name: MariaDB, MySQL, and the Ecosystem We Share05.3124-07-2026

Классификация: Пресс-релизы. Схожих патентов: 0. Схожих новостей: 9. Тональность: 0. Информативность: 5.92. Источник: mariadb.org.