sql

lepistane 2023-05-09T18:54:52.578479Z

First time this happens to me. I've created a view that is created from a select that does joins on 10 tables. Locally it works without a problem. When i deploy to to AWS RDS db.t4g.micro free tier query is not getting executed and i am getting 'connection refused' error. How do i go about fixing it or debugging it? I can't recreate the problem the problem

lepistane 2023-05-10T08:40:19.026129Z

sport was type text which mariadb had problems with, something with buffers when searching over it

lepistane 2023-05-10T08:40:25.122189Z

thanks for the help @camsaul

Cam Saul 2023-05-09T18:56:54.511459Z

Can you do a simple query like SELECT 1?

lepistane 2023-05-09T18:57:45.261529Z

yes

Cam Saul 2023-05-09T18:58:21.294679Z

So it only fails when you do CREATE VIEW?

Cam Saul 2023-05-09T18:59:30.486419Z

What DB are we talking about too? Postgres?

lepistane 2023-05-09T18:59:33.796349Z

view creation goes well. The problem is when i try to create queries using the view for example:

SELECT * FROM fixture_view_v2
where stream_name = 'NBA 1' 
works
SELECT * FROM fixture_view_v2
where stream_name = 'NBA 1' and start_date > <today>
also works but
SELECT * FROM fixture_view_v2
where sport = 'NBA'
breaks

lepistane 2023-05-09T19:00:03.304179Z

select * from fixture_view_v2 -> returns all of the data no problem

Cam Saul 2023-05-09T19:00:23.588509Z

The error is "connection refused"? And it happens consistently?

lepistane 2023-05-09T19:00:49.132869Z

i can copy stack trace, give me just a second. Yes. Every time i use sport in where clause it breaks

Cam Saul 2023-05-09T19:01:19.783349Z

Postgres?

Cam Saul 2023-05-09T19:02:15.906079Z

I wonder if "connection refused" is a red herring since clearly you can connect and fetch results

lepistane 2023-05-09T19:02:30.761819Z

mariadb

jkiss.dbeaver.model.impl.jdbc.JDBCException: SQL Error [08000]: Socket fail to connect to host:address=(host=abc)(port=3306)(type=primary). Connection refused (Connection refused)
	at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCConnectionImpl.prepareStatement(JDBCConnectionImpl.java:197)
	at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCConnectionImpl.prepareStatement(JDBCConnectionImpl.java:1)
	at org.jkiss.dbeaver.model.DBUtils.createStatement(DBUtils.java:1438)
	at org.jkiss.dbeaver.model.DBUtils.makeStatement(DBUtils.java:1404)
	at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeStatement(SQLQueryJob.java:558)
	at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.lambda$1(SQLQueryJob.java:491)
	at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:173)
	at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeSingleQuery(SQLQueryJob.java:498)
	at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.extractData(SQLQueryJob.java:917)
	at org.jkiss.dbeaver.ui.editors.sql.SQLEditor$QueryResultsContainer.readData(SQLEditor.java:3794)
	at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.lambda$0(ResultSetJobDataRead.java:123)
	at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:173)
	at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.run(ResultSetJobDataRead.java:121)
	at org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer$ResultSetDataPumpJob.run(ResultSetViewer.java:5061)
	at org.jkiss.dbeaver.model.runtime.AbstractJob.run(AbstractJob.java:105)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.sql.SQLNonTransientConnectionException: Socket fail to connect to host:address=(host=<>)(port=3306)(type=primary). Connection refused (Connection refused)
	at org.mariadb.jdbc.client.impl.ConnectionHelper.connectSocket(ConnectionHelper.java:136)
	at org.mariadb.jdbc.client.impl.StandardClient.<init>(StandardClient.java:103)
	at org.mariadb.jdbc.Driver.connect(Driver.java:70)
	at org.mariadb.jdbc.Driver.connect(Driver.java:101)
	at org.mariadb.jdbc.Driver.connect(Driver.java:27)
	at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.lambda$0(JDBCDataSource.java:206)
	at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.lambda$1(JDBCDataSource.java:225)
	at org.jkiss.dbeaver.utils.SecurityManagerUtils.wrapDriverActions(SecurityManagerUtils.java:96)
	at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.openConnection(JDBCDataSource.java:223)
	at org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource.openConnection(MySQLDataSource.java:448)
	at org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext.connect(JDBCExecutionContext.java:103)
	at org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext.connect(JDBCExecutionContext.java:88)
	at org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext.getConnection(JDBCExecutionContext.java:201)
	at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCConnectionImpl.getOriginal(JDBCConnectionImpl.java:60)
	at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCConnectionImpl.prepareStatement(JDBCConnectionImpl.java:244)
	at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCConnectionImpl.prepareStatement(JDBCConnectionImpl.java:146)
	... 15 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
	at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
	at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
	at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
	at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
	at java.base/java.net.Socket.connect(Unknown Source)
	at org.mariadb.jdbc.client.impl.ConnectionHelper.connectSocket(ConnectionHelper.java:130)
	... 30 more

lepistane 2023-05-09T19:05:20.704449Z

i see (first time i hear about red herring btw) So how/where/what to look for/into

Cam Saul 2023-05-09T19:05:27.935439Z

yeah based on that stack trace it looks like it just doesn't like that query, the question is why... are you sure that view has a sport column?

Cam Saul 2023-05-09T19:07:34.697089Z

when you call .prepareStatement() the JDBC driver will parse the SQL and usually throw an Exception if there is something wrong with the query, before you even call .execute()

lepistane 2023-05-09T19:08:45.648909Z

"CREATE VIEW fixture_view_v2 AS
select
 f.fixture_id,
 f.external_id,
 count(nmv.match_id) matches_played,
 f.start_date,
 t.tournament_id,
 t.name as tournament_name,
 t.sport,
....
yes i can see correct sport when i do select * from fixture_view_v2

Cam Saul 2023-05-09T19:09:18.583819Z

Can you do

SELECT * FROM fixture_view_v2 WHERE sport IS NOT NULL
?

Cam Saul 2023-05-09T19:10:52.633629Z

And can you query the table sport comes from directly? SELECT * FROM some_table WHERE sport = 'NBA'?

Cam Saul 2023-05-09T19:11:49.121149Z

I'm wondering if this could be some sort of permissions issue

lepistane 2023-05-09T19:11:55.161689Z

SELECT * FROM fixture_view_v2 WHERE sport IS NULL 
no results
SELECT * FROM fixture_view_v2 WHERE sport IS NOT NULL
returns all fixtures (count is = )
select * from tournament t 
where sport = 'NBA'
• yes it returns expected result

lepistane 2023-05-09T19:12:35.779939Z

i've ran all migrations and everything from the same account/credentials

Cam Saul 2023-05-09T19:13:57.447039Z

interesting. So WHERE sport = 'NBA' doesn't work, but sport IS NULL does. I think it's not a perms issue then. What's the column type of sport?

lepistane 2023-05-09T19:15:35.707349Z

is it possible that this free tier instance is weak and maybe memory runs out because the query is 'hairy'? sport is type text

Cam Saul 2023-05-09T19:18:03.419789Z

Maybe? You should be able to look at the memory usage in the AWS web interface for RDS

lepistane 2023-05-09T19:22:16.700219Z

it seems to me nothing is crazy

Cam Saul 2023-05-09T19:24:53.789649Z

Have you tried connecting with a CLI tool like mysql or something and running the query? If you did that then we could determine whether it's a genuine problem with the query itself or if something weird is going on with JDBC and the code around it

lepistane 2023-05-09T19:26:48.537449Z

i am gonna try now

lepistane 2023-05-09T19:29:38.793429Z

SELECT * FROM fixture_view_v2 where stream_name = 'NBA 1' and sport = 'NBA';
ERROR 2013 (HY000): Lost connection to MySQL server during query
No connection. Trying to reconnect...
ERROR 2003 (HY000): Can't connect to MySQL server on <HOST> (111)
ERROR: 
Can't connect to the server

lepistane 2023-05-09T19:30:06.579939Z

before that i did

mysql> SELECT * FROM fixture_view_v2 where stream_name = 'NBA 1'
....
42 rows in set (0.10 sec)

lepistane 2023-05-09T19:30:55.482169Z

so it's something weird 😕

lepistane 2023-05-09T19:31:37.335729Z

@camsaul ☝️

Cam Saul 2023-05-09T19:39:08.083949Z

Can you do DESCRIBE fixture_view_v2 to see if it gives us any useful info about sport?

lepistane 2023-05-09T19:53:12.887789Z

field type null ... sport text yes ...

Cam Saul 2023-05-09T20:07:40.404989Z

hmmm, I don't know. Maybe that theory about being to hairy could be the explanation