shardingsphere: Throw NPE at ExecutionContextBuilder.getPrimaryKeyColumns when execute sql

Throw NPE at ExecutionContextBuilder.getPrimaryKeyColumns when execute sql

Which version of ShardingSphere did you use?

5.0.0-RC1-SNAPSHOT

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-Proxy

Expected behavior

Actual behavior

mysql> select * from customer where id = 3;
ERROR 10002 (C1000): 2Unknown exception: [null]

log

java.lang.NullPointerException: null
        at org.apache.shardingsphere.infra.executor.sql.context.ExecutionContextBuilder.getPrimaryKeyColumns(ExecutionContextBuilder.java:129)
        at org.apache.shardingsphere.infra.executor.sql.context.ExecutionContextBuilder.getSQLRuntimeContext(ExecutionContextBuilder.java:81)
        at org.apache.shardingsphere.infra.executor.sql.context.ExecutionContextBuilder.build(ExecutionContextBuilder.java:71)
        at org.apache.shardingsphere.infra.executor.sql.context.ExecutionContextBuilder.build(ExecutionContextBuilder.java:57)
        at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.generateExecutionContext(KernelProcessor.java:53)
        at org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:67)
        at org.apache.shardingsphere.proxy.backend.text.query.QueryBackendHandler.execute(QueryBackendHandler.java:64)
        at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:62)
        at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:100)
        at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:76)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

Reason analyze (If you can)

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

  • prepare sql
create database spsqltest_sharding_00;
create database spsqltest_sharding_01;
  • config-test.yaml
schemaName: test
#
dataSourceCommon:
  username: root
  password: root135
  connectionTimeoutMilliseconds: 30000
  idleTimeoutMilliseconds: 60000
  maxLifetimeMilliseconds: 1800000
  maxPoolSize: 50
  minPoolSize: 1
  maintenanceIntervalMilliseconds: 30000
#
dataSources:
  ds_00:
    url: jdbc:mysql://127.0.0.1:3306/spsqltest_sharding_00?serverTimezone=UTC&useSSL=false
  ds_01:
    url: jdbc:mysql://127.0.0.1:3306/spsqltest_sharding_01?serverTimezone=UTC&useSSL=false
#
rules:
- !SHARDING
  tables:
    customer:
      actualDataNodes: ds_00.customer_000${0..1},ds_01.customer_000${2..3}
      databaseStrategy:
        standard:
          shardingColumn: id
          shardingAlgorithmName: database_inline
      tableStrategy:
        standard:
          shardingColumn: id
          shardingAlgorithmName: customer_inline
    customer_email:
      actualDataNodes: ds_00.customer_email_000${0..1},ds_01.customer_email_000${2..3}
      databaseStrategy:
        standard:
          shardingColumn: id
          shardingAlgorithmName: database_inline
      tableStrategy:
        standard:
          shardingColumn: id
          shardingAlgorithmName: customer_email_inline
  bindingTables:
    - customer,customer_email
  defaultDatabaseStrategy:
    none:
  defaultTableStrategy:
    none:

  shardingAlgorithms:
    database_inline:
      type: INLINE
      props:
        algorithm-expression: ds_0${id % 2}
    customer_inline:
      type: INLINE
      props:
        algorithm-expression: customer_000${id % 4}
    customer_email_inline:
      type: INLINE
      props:
        algorithm-expression: customer_email_000${id % 4}
  • execute sql
select * from customer where id = 3;

Example codes for reproduce this issue (such as a github link).

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (23 by maintainers)

Most upvoted comments

Hi @tristaZero @xbkaishui I have test my scenarios , that work well.

  • Test selectcreate table and drop table when table not exsits before ss start.
mysql> show tables;
Empty set (0.01 sec)

mysql> sctl:explain select * from customer where id = 3;
+-----------------+------------------------------------------+
| datasource_name | sql                                      |
+-----------------+------------------------------------------+
| ds_01           | select * from customer_0003 where id = 3 |
+-----------------+------------------------------------------+
1 row in set (0.00 sec)

mysql> select * from customer where id = 3;
ERROR 1146 (42S02): Table 'spsqltest_sharding_01.customer_0003' doesn't exist
mysql> CREATE TABLE `customer` (
    ->   `id` bigint(20) NOT NULL COMMENT '主键ID',
    ->   `party_id` bigint(20) NOT NULL COMMENT '用户ID',
    ->    `status` smallint(6) DEFAULT NULL COMMENT '状态:1-有效,0-无效  待删除字段',
    ->   PRIMARY KEY (`id`),
    ->   KEY `party_id_index` (`party_id`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='客户表';
Query OK, 0 rows affected (0.44 sec)

mysql> show tables;
+---------------------------------+
| Tables_in_spsqltest_sharding_01 |
+---------------------------------+
| customer                        |
+---------------------------------+
1 row in set (0.01 sec)

mysql> insert into customer (id, party_id, status) values (1, 1, 1), (2, 1, 2), (3, 1, 3);
Query OK, 3 rows affected (0.03 sec)

mysql> sctl:explain select * from customer where id = 3;
+-----------------+------------------------------------------+
| datasource_name | sql                                      |
+-----------------+------------------------------------------+
| ds_01           | select * from customer_0003 where id = 3 |
+-----------------+------------------------------------------+
1 row in set (0.01 sec)

mysql> select * from customer where id = 3;
+----+----------+--------+
| id | party_id | status |
+----+----------+--------+
|  3 |        1 |      3 |
+----+----------+--------+
1 row in set (0.01 sec)

mysql> drop table customer;
Query OK, 0 rows affected (0.05 sec)

mysql> show tables;
Empty set (0.01 sec)

mysql> sctl:explain select * from customer where id = 3;
+-----------------+------------------------------------------+
| datasource_name | sql                                      |
+-----------------+------------------------------------------+
| ds_01           | select * from customer_0003 where id = 3 |
+-----------------+------------------------------------------+
1 row in set (0.01 sec)

mysql> select * from customer where id = 3;
ERROR 1146 (42S02): Table 'spsqltest_sharding_01.customer_0003' doesn't exist

  • Test selectcreate table and drop table when table exsits before ss start.
mysql> show tables;
+---------------------------------+
| Tables_in_spsqltest_sharding_01 |
+---------------------------------+
| customer                        |
+---------------------------------+
1 row in set (0.18 sec)

mysql> sctl:explain select * from customer where id = 3;
+-----------------+------------------------------------------+
| datasource_name | sql                                      |
+-----------------+------------------------------------------+
| ds_01           | select * from customer_0003 where id = 3 |
+-----------------+------------------------------------------+
1 row in set (0.28 sec)

mysql> select * from customer where id = 3;
+----+----------+--------+
| id | party_id | status |
+----+----------+--------+
|  3 |        1 |      3 |
+----+----------+--------+
1 row in set (0.01 sec)

mysql> drop table customer;
Query OK, 0 rows affected (0.11 sec)

mysql> show tables;
Empty set (0.01 sec)

mysql> sctl:explain select * from customer where id = 3;
+-----------------+------------------------------------------+
| datasource_name | sql                                      |
+-----------------+------------------------------------------+
| ds_01           | select * from customer_0003 where id = 3 |
+-----------------+------------------------------------------+
1 row in set (0.01 sec)

mysql> select * from customer where id = 3;
ERROR 1146 (42S02): Table 'spsqltest_sharding_01.customer_0003' doesn't exist

please assign to me