3

I am writing a CUDA code which requires data from database I want to get 400 random rows from a database stored in PostgreSQL. If I retrieve each of the rows sequentially, it will make my code very slow and it will not serve the purpose of parallelism and speedup. So, I want some C library or function which can create multiple connections with PostgreSQL and retrieve data faster.

Is there something in C which will help me do that?

5
  • Have you already tried libpq (postgresql.org/docs/9.1/static/libpq.html ) and opening multiple nonblocking connections with PQconnectStart()? Commented Aug 27, 2012 at 10:31
  • Did you also tried to run PostgreSQL as in-memory database to check performance boost ? Commented Aug 27, 2012 at 10:37
  • Continued: I doubt if you can retrieve data faster with or without GPU support if data storage is on HDD where physical movement of head is required for reading every record. So to be able to retrieve data in fast mode - one needs to store data in some random access devices such as RAM / SSD / VRAM. And only then next step is to try to write custom code which retrieves some data in parallel. But again probably this step must be implemented by PostgreSQL developers as part of database engine. Commented Aug 27, 2012 at 10:50
  • Yes, I think I will try libpq and let you all know what happens. Thanks for the help. Commented Aug 30, 2012 at 11:58
  • you could also use a connection pooler. pgbouncer is great. we used to to speed up our stuff. it will let you keep your connections alive, and you don't have to write any code. just use config files. Commented Sep 5, 2012 at 13:34

1 Answer 1

1

Perhaps a query like this would suit you:

SELECT * FROM tablename ORDER BY RANDOM() LIMIT 400;
Sign up to request clarification or add additional context in comments.

1 Comment

Not a terribly efficient way of getting random rows on the database site, but yes, that was my thought too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.