This repository has been archived on 2025-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
lwb6/legacyworlds-server-data/db-structure/tests/utils/locks-finder.sql
Emmanuel BENOîT 74b6f2ab09 Mining computation update
* Added various views and helper functions used by the mining
computation but which may be re-used in other parts.

* Added mining computation update type and associated update function

* New constants: game.resources.weightBase (the value used to compute
weights from mining settings) and game.resources.extraction (the
quantity extracted in a day from a full provider at difficulty 0)
2012-01-16 12:35:20 +01:00

43 lines
No EOL
834 B
PL/PgSQL

/*
* Utility functions used by unit tests
*
* Row lock checks
*/
CREATE TYPE _locks_entry AS (
ctid tid ,
shared BOOLEAN ,
exclusive BOOLEAN
);
CREATE OR REPLACE FUNCTION _get_locks_on(
IN _table TEXT )
RETURNS SETOF _locks_entry
STRICT VOLATILE
AS $$
DECLARE
_page INT;
_pages INT;
_record RECORD;
_return _locks_entry;
BEGIN
SELECT INTO _pages pg_relation_size( _table ) / 8192;
FOR _page IN 0 .. ( _pages - 1 )
LOOP
FOR _record IN SELECT t_ctid , t_infomask
FROM heap_page_items( get_raw_page( _table , _page ) )
WHERE t_xmax::text::int > ( txid_current( ) & x'ffffffff'::bigint )
LOOP
_return := ROW( _record.t_ctid ,
_record.t_infomask & x'80'::int <> 0 ,
_record.t_infomask & x'40'::int <> 0 );
RETURN NEXT _return;
END LOOP;
END LOOP;
END;
$$ LANGUAGE PLPGSQL;