![]() ![]() The replicas poll the binlog and start executing the query as soon as it appears. The primary server writes the query to the binlog when the transaction is committed. Writes on the primary server are executed in parallel, but they are executed in serial when they are replicated to the replicas. Due to our unabashed Wikipedia-centrism, we often just use the replication-friendly version, but if you like, you can use wfGetLB () -> getServerCount () > 1 to check to see if replication is in use.ĭie Verzögerung tritt vor allem dann auf, wenn große Schreibanfragen an den Master gesendet werden. It's often the case that the best algorithm to use for a given task depends on whether or not replication is in use. It is important to understand the issues associated with this setup if you want to write code destined for Wikipedia. Large installations of MediaWiki such as Wikipedia, use a large set of replica MySQL servers replicating writes made to a primary MySQL server. ** * backward compatibility * 1.31.15 * 1.35.3 * define( 'DB_PRIMARY', ILoadBalancer::DB_PRIMARY ) * DB_PRIMARY remains undefined in MediaWiki before v1.31.15/v1.35.3 * 1.28.0 * define( 'DB_REPLICA', ILoadBalancer::DB_REPLICA ) * DB_REPLICA remains undefined in MediaWiki before v1.28 */ defined ( 'DB_PRIMARY' ) or define ( 'DB_PRIMARY', DB_MASTER ) defined ( 'DB_REPLICA' ) or define ( 'DB_REPLICA', DB_SLAVE ) $res = WrapperClass :: getQueryFoo () class WrapperClass Once you have a row object, you can use the -> operator to access a specific field. You can access individual rows of the result using a foreach loop. The array construction for $conds is somewhat limited it can only do equality and IS NULL relationships (i.e. The values for table names (1st argument) or field names (2nd argument) must not be user controlled. If you pass in strings to the third or fifth argument, you must manually use Database::addQuotes() on your values as you construct the string, as the wrapper will not do this for you. SELECT wl_user FROM ` watchlist ` INNER JOIN ` user_properties ` ON (( wl_user = up_user )) WHERE ( wl_user != 1 ) AND wl_namespace = '0' AND wl_title = 'Main_page' AND up_property = 'enotifwatchlistpages'Įrweiterung:OrphanedTalkPages bietet ein Beispiel für die Verwendung von Tabellen- Aliasen in Abfragen.Īrguments are either single values (such as 'category' and 'cat_pages > 0') or arrays, if more than one value is passed for an argument position (such as ). Particularly see Database::select for an explanation of the $table, $vars, $conds, $fname, $options, and $join_conds parameters that are used by many of the other wrapper functions. For a detailed description of the parameters of the wrapper functions, please refer to class Database's docs. In the following, the available wrapper functions are listed. There is support for PostgreSQL, but it is not as stable as MySQL. There is also good support for SQLite, however it is much slower than MySQL or MariaDB. Currently the best support is for MySQL/MariaDB. Please keep in mind that failing to use addQuotes() properly can introduce severe security holes into your wiki.Īnother important reason to use the high level methods rather than constructing your own queries is to ensure that your code will run properly regardless of the database type. If you really need to make your own SQL, please read the documentation for tableName() and addQuotes(). They can take care of things like table prefixes and escaping for you under some circumstances. We provide a query() function for raw SQL, but the wrapper functions like select() and insert() are usually more convenient. $pageIds is an array of page IDs, and $pageId is a single page ID. In these examples, $pageRow is an row object as in the foreach example above, Equivalent of: // $rows = fetchResultSet() // $row = $rows $pageRow = $dbr -> newSelectQueryBuilder () -> select ( ) -> from ( 'page' ) -> orderBy ( 'page_touched', SelectQueryBuilder :: SORT_DESC ) -> caller ( _METHOD_ ) -> fetchRow () // Equivalent of: // $rows = fetchResultSet() // $ids = array_map( fn( $row ) => $row->page_id, $rows ) $pageIds = $dbr -> newSelectQueryBuilder () -> select ( 'page_id' ) -> from ( 'page' ) -> where ( ) -> caller ( _METHOD_ ) -> fetchFieldValues () // Equivalent of: // $rows = fetchResultSet() // $id = $row->page_id $pageId = $dbr -> newSelectQueryBuilder () -> select ( 'page_id' ) -> from ( 'page' ) -> where ( ) -> caller ( _METHOD_ ) -> fetchField () ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |