question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generate a unexpected Actual SQL

See original GitHub issue

ShardingSphere version: 5.1.0 Database: Mysql

Properties:

spring:
  shardingsphere:
    datasource:
      names: db0
    props:
      sql-show: true
    rules:
      sharding:
        tables:
          book:
            actual-data-nodes: db0.book_$->{0..2}
            table-strategy:
              standard:
                sharding-column: id
                sharding-algorithm-name: table-inline
            key-generate-strategy:
              column: id
              key-generator-name: snowflake
        sharding-algorithms:
          table-inline:
            type: INLINE
            props:
              algorithm-expression: book_$->{id % 3}

Logic SQL:

SELECT
	UPPER(
	LEFT ( bg.class_no, 1 )) class_char,
	count(
	DISTINCT ( bg.class_no )) class_num,
	count( b.id ) book_num,
	sum( b.price ) sum_price 
FROM
	book b
	JOIN bibliography bg ON b.bibliography_id = bg.id 
WHERE
	b.user_id = ? 
GROUP BY
	class_char

Using logic sql and no sharding result:

classChar classNum bookNum sumPrice
A 2 3 89.10
B 2 3 121.60
D 2 2 38.80
Z 1 2 5.52

Actual SQL:

SELECT DISTINCT
	UPPER(
	LEFT ( bg.class_no, 1 )) class_char,
	bg.class_no class_num,
	count( b.id ) book_num,
	sum( b.price ) sum_price 
FROM
	book_0 b
	JOIN bibliography bg ON b.bibliography_id = bg.id 
WHERE
	b.user_id = ? 
ORDER BY
	class_char ASC

unexpected result:

classChar classNum bookNum sumPrice
A 2 6 202.90
Z 1 4 52.12

Maybe it is a bug? I don’t know. 😦 Please give me some help. The sql file: demo1.zip

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
github-actions[bot]commented, Oct 8, 2022

Hello , this issue has not received a reply for several days. This issue is supposed to be closed.

0reactions
strongduanmucommented, Jul 16, 2022

@cucuzi I will check the rewrite logic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected values (values being added) to column/output ...
Unexpected values (values being added) to column/output generated/formatted incorrectly from SQL ... Above is the table I have. I am asked to:.
Read more >
Cannot generate SSPI context when connecting to SQL Server
Start KerberosConfigMgr.exe from the %SystemDrive%:\Program Files\Microsoft\Kerberos Configuration Manager folder. Then, use a domain account ...
Read more >
Resolve custom SQL data source exception error in QuickSight
"Your database generated a SQL exception. This can be caused by query timeouts, resource constraints, unexpected DDL alterations before or ...
Read more >
Common SQL syntax errors and how to resolve them
In this article, we are going to describe some of the most common SQL syntax errors, and explains how you can resolve these...
Read more >
Optimize SQL Queries with CASE Expressions in Unexpected ...
So, I'm writing a series on using Case Expressions in unexpected ways. This is part 2 in the series:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found