support older PostGreSQL versions (#4999)
* support older PostGreSQL versions * documentation accuracy * improve performance by affecting less rows in UPDATE queriesmaster
parent
73fdb63597
commit
11df7e886a
|
@ -178,7 +178,7 @@ ENABLE_FREETYPE - Build with FreeType2; Allows using TTF fonts
|
||||||
ENABLE_GETTEXT - Build with Gettext; Allows using translations
|
ENABLE_GETTEXT - Build with Gettext; Allows using translations
|
||||||
ENABLE_GLES - Search for Open GLES headers & libraries and use them
|
ENABLE_GLES - Search for Open GLES headers & libraries and use them
|
||||||
ENABLE_LEVELDB - Build with LevelDB; Enables use of LevelDB map backend
|
ENABLE_LEVELDB - Build with LevelDB; Enables use of LevelDB map backend
|
||||||
ENABLE_POSTGRESQL - Build with libpq; Enables use of PostgreSQL map backend (PostgreSQL 9.5 or greater required)
|
ENABLE_POSTGRESQL - Build with libpq; Enables use of PostgreSQL map backend (PostgreSQL 9.5 or greater recommended)
|
||||||
ENABLE_REDIS - Build with libhiredis; Enables use of Redis map backend
|
ENABLE_REDIS - Build with libhiredis; Enables use of Redis map backend
|
||||||
ENABLE_SPATIAL - Build with LibSpatial; Speeds up AreaStores
|
ENABLE_SPATIAL - Build with LibSpatial; Speeds up AreaStores
|
||||||
ENABLE_SOUND - Build with OpenAL, libogg & libvorbis; in-game Sounds
|
ENABLE_SOUND - Build with OpenAL, libogg & libvorbis; in-game Sounds
|
||||||
|
|
|
@ -80,12 +80,12 @@ void Database_PostgreSQL::connectToDatabase()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We are using UPSERT feature from PostgreSQL 9.5
|
* We are using UPSERT feature from PostgreSQL 9.5
|
||||||
* to have the better performance,
|
* to have the better performance where possible.
|
||||||
* set the minimum version to 90500
|
|
||||||
*/
|
*/
|
||||||
if (m_pgversion < 90500) {
|
if (m_pgversion < 90500) {
|
||||||
throw DatabaseException("PostgreSQL database error: "
|
warningstream << "Your PostgreSQL server lacks UPSERT "
|
||||||
"Server version 9.5 or greater required.");
|
<< "support. Use version 9.5 or better if possible."
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
infostream << "PostgreSQL Database: Version " << m_pgversion
|
infostream << "PostgreSQL Database: Version " << m_pgversion
|
||||||
|
@ -125,11 +125,25 @@ void Database_PostgreSQL::initStatements()
|
||||||
"WHERE posX = $1::int4 AND posY = $2::int4 AND "
|
"WHERE posX = $1::int4 AND posY = $2::int4 AND "
|
||||||
"posZ = $3::int4");
|
"posZ = $3::int4");
|
||||||
|
|
||||||
prepareStatement("write_block",
|
if (m_pgversion < 90500) {
|
||||||
|
prepareStatement("write_block_insert",
|
||||||
|
"INSERT INTO blocks (posX, posY, posZ, data) SELECT "
|
||||||
|
"$1::int4, $2::int4, $3::int4, $4::bytea "
|
||||||
|
"WHERE NOT EXISTS (SELECT true FROM blocks "
|
||||||
|
"WHERE posX = $1::int4 AND posY = $2::int4 AND "
|
||||||
|
"posZ = $3::int4)");
|
||||||
|
|
||||||
|
prepareStatement("write_block_update",
|
||||||
|
"UPDATE blocks SET data = $4::bytea "
|
||||||
|
"WHERE posX = $1::int4 AND posY = $2::int4 AND "
|
||||||
|
"posZ = $3::int4");
|
||||||
|
} else {
|
||||||
|
prepareStatement("write_block",
|
||||||
"INSERT INTO blocks (posX, posY, posZ, data) VALUES "
|
"INSERT INTO blocks (posX, posY, posZ, data) VALUES "
|
||||||
"($1::int4, $2::int4, $3::int4, $4::bytea) "
|
"($1::int4, $2::int4, $3::int4, $4::bytea) "
|
||||||
"ON CONFLICT ON CONSTRAINT blocks_pkey DO "
|
"ON CONFLICT ON CONSTRAINT blocks_pkey DO "
|
||||||
"UPDATE SET data = $4::bytea");
|
"UPDATE SET data = $4::bytea");
|
||||||
|
}
|
||||||
|
|
||||||
prepareStatement("delete_block", "DELETE FROM blocks WHERE "
|
prepareStatement("delete_block", "DELETE FROM blocks WHERE "
|
||||||
"posX = $1::int4 AND posY = $2::int4 AND posZ = $3::int4");
|
"posX = $1::int4 AND posY = $2::int4 AND posZ = $3::int4");
|
||||||
|
@ -218,7 +232,12 @@ bool Database_PostgreSQL::saveBlock(const v3s16 &pos,
|
||||||
};
|
};
|
||||||
const int argFmt[] = { 1, 1, 1, 1 };
|
const int argFmt[] = { 1, 1, 1, 1 };
|
||||||
|
|
||||||
execPrepared("write_block", ARRLEN(args), args, argLen, argFmt);
|
if (m_pgversion < 90500) {
|
||||||
|
execPrepared("write_block_update", ARRLEN(args), args, argLen, argFmt);
|
||||||
|
execPrepared("write_block_insert", ARRLEN(args), args, argLen, argFmt);
|
||||||
|
} else {
|
||||||
|
execPrepared("write_block", ARRLEN(args), args, argLen, argFmt);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue