Solution 1:

Always provide SHOW CREATE TABLE when asking about performance.

It sounds like you are missing INDEX(hash). (PRIMARY KEY(hash) or UNIQUE(hash), if present is such an index.)

Solution 2:

This table got around 30 million records ...
SELECT * from `table` WHERE hash='blahblahblah'; ...
This query is taking around 40 seconds to execute

Is the hash column indexed?
40 seconds sounds perfectly reasonable for MariaDB to trawl sequentially through 30 million records.

BTW, if your table really is called table, then consider changing it to something else, if for no other reason than you're very, very likely to have more than one table and having a database full of table1, table2, table3, etc., will start to make your head hurt very quickly.

Also, you should never use reserved words as identifiers for tables, columns, etc.
It will come back and bite you at some point.