manticoresoftware / manticoresearch

Easy to use open source fast database for search | Good alternative to Elasticsearch now | Drop-in replacement for E in the ELK soon
https://manticoresearch.com
GNU General Public License v3.0
9.02k stars 506 forks source link

Using expression returns a wrong value for a joined table #2414

Open anStalf opened 3 months ago

anStalf commented 3 months ago

Bug Description:

In the manticore, the count is not calculated by multiplying it by the price.

How it's work in MySQL:

create database test;
use test;
show tables;
create table products (art integer, name text, info text, price integer);
insert into products (art, name, info, price) values (1, 'Product 1', 'First demo product', 10), (2, 'Product 2', 'Second demo product', 15), (3, 'Product 3', 'Third demo product', 22), (4, 'Product 4', 'Fourth demo product', 8), (5, 'Product 5', 'Fifth demo product', 99);
select * from products;
create table basket (user_id integer, art integer, count integer);
insert into basket (user_id, art, count) values (1, 3, 1), (1, 2, 2), (1, 5, 4);
select products.name name, count, products.price as price, (price * count) as total from basket left join products on basket.art=products.art where user_id = 1;

RESULT

+-----------+-------+-------+-------+
| name      | count | price | total |
+-----------+-------+-------+-------+
| Product 3 |     1 |    22 |    22 |
| Product 2 |     2 |    15 |    30 |
| Product 5 |     4 |    99 |   396 |
+-----------+-------+-------+-------+
3 rows in set (0.00 sec)

How it's work in Manticore:

create table products (art integer, name string, info text, price integer) morphology = 'stem_en';
insert into products (art, name, info, price) values (1, 'Product 1', 'First demo product', 10), (2, 'Product 2', 'Second demo product', 15), (3, 'Product 3', 'Third demo product', 22), (4, 'Product 4', 'Fourth demo product', 8), (5, 'Product 5', 'Fifth demo product', 99);
create table basket (user_id integer, art integer, count integer);
insert into basket (user_id, art, count) values (1, 3, 1), (1, 2, 2), (1, 5, 4);
select products.name name, count, products.price as price, (price * count) as total from basket left join products on basket.art=products.art where user_id = 1;

RESULT:

+-----------+-------+-------+-------+
| name      | count | price | total |
+-----------+-------+-------+-------+
| Product 3 |     1 |    22 |     0 |
| Product 2 |     2 |    15 |     0 |
| Product 5 |     4 |    99 |     0 |
+-----------+-------+-------+-------+
3 rows in set (0.01 sec)
--- 3 out of 3 results in 0ms ---

Manticore Search Version:

6.3.0

Operating System Version:

docker

Have you tried the latest development version?

None

Internal Checklist:

To be completed by the assignee. Check off tasks that have been completed or are not applicable.

- [ ] Implementation completed - [ ] Tests developed - [ ] Documentation updated - [ ] Documentation reviewed - [ ] Changelog updated
anStalf commented 3 months ago

Manticore 6.3.2 with the same problem. Checked:

show version;
+-----------+----------------------------------+
| Component | Version                          |
+-----------+----------------------------------+
| Daemon    | 6.3.2 c296dc7c8@24062606         |
| Columnar  | columnar 2.3.0 88a01c3@24052206  |
| Secondary | secondary 2.3.0 88a01c3@24052206 |
| KNN       | knn 2.3.0 88a01c3@24052206       |
| Buddy     | buddy v2.3.10                    |
+-----------+----------------------------------+
5 rows in set (0.01 sec)
+-----------+-------+-------+-------+
| name      | count | price | total |
+-----------+-------+-------+-------+
| Product 3 |     1 |    22 |     0 |
| Product 2 |     2 |    15 |     0 |
| Product 5 |     4 |    99 |     0 |
+-----------+-------+-------+-------+
3 rows in set (0.00 sec)
--- 3 out of 3 results in 0ms ---
sanikolaev commented 3 months ago

MRE

mysql> drop table if exists j; create table j(a int); drop table if exists j2; create table j2(b int); insert into j values(1, 1); insert into j2 values(1, 2); select a, j2.b as b2, a * b2 from j left join j2 on j.id = j2.id;
--------------
drop table if exists j
--------------

Query OK, 0 rows affected (0.01 sec)

--------------
create table j(a int)
--------------

Query OK, 0 rows affected (0.00 sec)

--------------
drop table if exists j2
--------------

Query OK, 0 rows affected (0.00 sec)

--------------
create table j2(b int)
--------------

Query OK, 0 rows affected (0.00 sec)

--------------
insert into j values(1, 1)
--------------

Query OK, 1 row affected (0.00 sec)

--------------
insert into j2 values(1, 2)
--------------

Query OK, 1 row affected (0.00 sec)

--------------
select a, j2.b as b2, a * b2 from j left join j2 on j.id = j2.id
--------------

+------+------+--------+
| a    | b2   | a * b2 |
+------+------+--------+
|    1 |    2 |      0 |
+------+------+--------+
1 row in set (0.00 sec)
--- 1 out of 1 results in 0ms ---

Expected:

+------+------+--------+
| a    | b2   | a * b2 |
+------+------+--------+
|    1 |    2 |      2 |
+------+------+--------+

Reproduced in:

Manticore 6.3.3 fb447b264@24071413 dev (columnar 2.3.1 42f2b06@24070110) (secondary 2.3.1 42f2b06@24070110) (knn 2.3.1 42f2b06@24070110)