issue with cmdline when input ";" multiple times

Asked by Alvin Peng

In stado cmdline, when I try to input a single ";", the "execute" results seem confusing.
The cmdline operation logs are shown below. (The "show tables" command's result is not returned timely)

Is this a known issue? Please help answer. Thanks a lot!!

Regards,
Alvin

==================
Stado -> show databases;
+----------------------------------+
| DATABASE | STATUS | NODES |
+----------------------------------+
| test | Started | 1,2,3,4,5,6 |
| test2 | Started | 1,2,3 |
+----------------------------------+
2 row(s).

Stado -> ;
OK

Stado -> ;
+----------------------------------+
| DATABASE | STATUS | NODES |
+----------------------------------+
| test | Started | 1,2,3,4,5,6 |
| test2 | Started | 1,2,3 |
+----------------------------------+
2 row(s).

Stado -> show tables;
OK

Stado -> show databases;
+----------------------------------+
| DATABASE | STATUS | NODES |
+----------------------------------+
| test | Started | 1,2,3,4,5,6 |
| test2 | Started | 1,2,3 |
+----------------------------------+
2 row(s).

Stado -> ;
+---------------------------------------------------+
| TABLE | TABLE_PARTITIONING_COLUMN | TABLE_NODES |
+---------------------------------------------------+
| test2 | id | 1,2,3 |
| testpwj | id | 1,2,3 |
+---------------------------------------------------+
2 row(s).

Stado -> ;
+----------------------------------+
| DATABASE | STATUS | NODES |
+----------------------------------+
| test | Started | 1,2,3,4,5,6 |
| test2 | Started | 1,2,3 |
+----------------------------------+
2 row(s).

Stado -> ;
OK

Stado -> ;
+----------------------------------+
| DATABASE | STATUS | NODES |
+----------------------------------+
| test | Started | 1,2,3,4,5,6 |
| test2 | Started | 1,2,3 |
+----------------------------------+
2 row(s).

Stado ->

Question information

Language:
English Edit question
Status:
Solved
For:
Stado Edit question
Assignee:
No assignee Edit question
Solved by:
Alvin Peng
Solved:
Last query:
Last reply:
Revision history for this message
Jim Mlodgenski (jim-cirrusql) said :
#1

That's odd. Looks like a bug to me.

I would recommend that you use PostgreSQL's psql command line utility to connect to Stado. It has many more features.

Revision history for this message
Alvin Peng (pengalvin) said :
#2

Thanks Jim! I try, and psql is ok for me.

Revision history for this message
Launchpad Janitor (janitor) said :
#3

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Alvin Peng (pengalvin) said :
#4

Hi Jim,

For this bug, I found a potential cause in PgProtocalSession.java run() method:

                    case PgProtocolMessage.MESSAGE_TYPE_PARSE:
                        setState(SESSION_STATE_QUERY);
                        String statementID = request.getString();
                        String statement = request.getString().trim();
                        if (statement.length() == 0) {
                            writeToChannel(
                                    PgProtocolMessage.MSG_EMPTY_QUERY_RESPONSE,
                                    channel);
                            setState(SESSION_STATE_READY);
                        }

when a ";" is input from CmdLine, server will responses with a "MSG_EMPTY_QUERY_RESPONSE" in the parse phase. However, in later bind, describe, execute phase, server will still try to process the incoming message. And at last

                    case PgProtocolMessage.MESSAGE_TYPE_SYNC:
                        error = false;
                        setState(SESSION_STATE_READY);

the "MESSAGE_TYPE_SYNC" is received, server will set the state to "READY" again. The difference is it set "error = false".

Therefore, I think setting "error = true" in the parse phase if the query is empty will solve this bug.
In "sync" phase, server will set "error = false" again.

Actually, when using psql, input ";" will cause an error:

test=> ;
ERROR: Encountered ";" at line 1, column 1.

Please correct me if I misunderstand.

Regards,
Alvin

Revision history for this message
Alvin Peng (pengalvin) said :
#5

The setState(SESSION_STATE_READY) is called twice for an empty query.
And in setState(SESSION_STATE_READY) MESSAGE_TYPE_READY_FOR_QUERY is sent.
We can check the newState first before update?

void setState(int newState) throws IOException {

        // if the state is not changed, do not need to send the MESSAGE_TYPE_READY_FOR_QUERY message
     if(sessionState == newState)
      return;

Revision history for this message
Alvin Peng (pengalvin) said :
#6

Hi Jim,

I've tested with the code changes:
1. set error = true in parse phase when the query is empty
2. check newState in setState(), if state not changed, do not send the MESSAGE_TYPE_READY_FOR_QUERY.

Then the ";" issue does not appear again.

Regards,
Alvin

Revision history for this message
Alvin Peng (pengalvin) said :
#7

Bug #1019129(Bug when handling empty query) was created for the issue. Close this question. More details please refer to the Bug https://bugs.launchpad.net/stado/+bug/1019129