r66681 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66680‎ | r66681 | r66682 >
Date:04:47, 20 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r66680 - copied improvements to the light SQL store
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStoreLight.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStoreLight.php
@@ -929,57 +929,98 @@
930930 */
931931 protected function setupTables( $verbose, $db ) {
932932 global $wgDBtype;
933 - extract( $db->tableNames( 'smw_ids', 'smw_spec2', 'smw_conccache', 'smw_conc2' ) );
934 - $reportTo = $verbose ? $this:null; // use $this to report back from static SMWSQLHelpers
935 - // repeatedly used DB field types defined here for convenience
936 - $dbtypes = array( 't' => SMWSQLHelpers::getStandardDBType( 'title' ),
937 - 'u' => ( $wgDBtype == 'postgres' ? 'TEXT':'VARCHAR(63) binary' ),
938 - 'l' => SMWSQLHelpers::getStandardDBType( 'blob' ),
939 - 'f' => ( $wgDBtype == 'postgres' ? 'DOUBLE PRECISION':'DOUBLE' ),
940 - 'i' => ( $wgDBtype == 'postgres' ? 'INTEGER':'INT(8)' ),
941 - 'j' => ( $wgDBtype == 'postgres' ? 'INTEGER':'INT(8) UNSIGNED' ),
942 - 'p' => SMWSQLHelpers::getStandardDBType( 'id' ),
943 - 'n' => SMWSQLHelpers::getStandardDBType( 'namespace' ),
944 - 'w' => SMWSQLHelpers::getStandardDBType( 'iw' ) );
 933+
 934+ $reportTo = $verbose ? $this : null; // Use $this to report back from static SMWSQLHelpers.
 935+
 936+ // Repeatedly used DB field types defined here for convenience.
 937+ $dbtypes = array(
 938+ 't' => SMWSQLHelpers::getStandardDBType( 'title' ),
 939+ 'u' => ( $wgDBtype == 'postgres' ? 'TEXT' : 'VARCHAR(63) binary' ),
 940+ 'l' => SMWSQLHelpers::getStandardDBType( 'blob' ),
 941+ 'f' => ( $wgDBtype == 'postgres' ? 'DOUBLE PRECISION' : 'DOUBLE' ),
 942+ 'i' => ( $wgDBtype == 'postgres' ? 'INTEGER' : 'INT(8)' ),
 943+ 'j' => ( $wgDBtype == 'postgres' ? 'INTEGER' : 'INT(8) UNSIGNED' ),
 944+ 'p' => SMWSQLHelpers::getStandardDBType( 'id' ),
 945+ 'n' => SMWSQLHelpers::getStandardDBType( 'namespace' ),
 946+ 'w' => SMWSQLHelpers::getStandardDBType( 'iw' )
 947+ );
945948
946 - // DB update: field renaming between SMW 1.3 and SMW 1.4
947 - if ( ( $db->tableExists( $smw_spec2 ) ) && ( $db->fieldExists( $smw_spec2, 'sp_id', 'SMWSQLStoreLight::setup' ) ) ) {
 949+ $smw_spec2 = $db->tableName( 'smw_spec2' );
 950+
 951+ // DB update: field renaming between SMW 1.3 and SMW 1.4.
 952+ if ( ( $db->tableExists( $smw_spec2 ) ) && ( $db->fieldExists( $smw_spec2, 'sp_id', 'SMWSQLStore2::setup' ) ) ) {
948953 if ( $wgDBtype == 'postgres' ) {
949 - $db->query( "ALTER TABLE $smw_spec2 ALTER COLUMN sp_id RENAME TO p_id", 'SMWSQLStoreLight::setup' );
 954+ $db->query( "ALTER TABLE $smw_spec2 ALTER COLUMN sp_id RENAME TO p_id", 'SMWSQLStore2::setup' );
950955 } else {
951 - $db->query( "ALTER TABLE $smw_spec2 CHANGE `sp_id` `p_id` " . $dbtypes['p'] . " NOT NULL", 'SMWSQLStoreLight::setup' );
 956+ $db->query( "ALTER TABLE $smw_spec2 CHANGE `sp_id` `p_id` " . $dbtypes['p'] . " NOT NULL", 'SMWSQLStore2::setup' );
952957 }
953958 }
954959
955 - // set up table for internal IDs used in this store:
956 - SMWSQLHelpers::setupTable( $smw_ids,
957 - array( 'smw_id' => $dbtypes['p'] . ' NOT NULL' . ( $wgDBtype == 'postgres' ? ' PRIMARY KEY':' KEY AUTO_INCREMENT' ),
958 - 'smw_namespace' => $dbtypes['n'] . ' NOT NULL',
959 - 'smw_title' => $dbtypes['t'] . ' NOT NULL',
960 - 'smw_iw' => $dbtypes['w'],
961 - 'smw_sortkey' => $dbtypes['t'] . ' NOT NULL' ), $db, $reportTo );
962 - SMWSQLHelpers::setupIndex( $smw_ids, array( 'smw_id', 'smw_title,smw_namespace,smw_iw', 'smw_sortkey' ), $db );
 960+ // Set up table for internal IDs used in this store:
 961+ SMWSQLHelpers::setupTable(
 962+ 'smw_ids',
 963+ array(
 964+ 'smw_id' => $dbtypes['p'] . ' NOT NULL' . ( $wgDBtype == 'postgres' ? ' PRIMARY KEY' : ' KEY AUTO_INCREMENT' ),
 965+ 'smw_namespace' => $dbtypes['n'] . ' NOT NULL',
 966+ 'smw_title' => $dbtypes['t'] . ' NOT NULL',
 967+ 'smw_iw' => $dbtypes['w'],
 968+ 'smw_sortkey' => $dbtypes['t'] . ' NOT NULL'
 969+ ),
 970+ $db,
 971+ $reportTo
 972+ );
 973+
 974+ SMWSQLHelpers::setupIndex( 'smw_ids', array( 'smw_id', 'smw_title,smw_namespace,smw_iw', 'smw_sortkey' ), $db );
963975
964 - // set up concept cache: member elements (s)->concepts (o)
965 - SMWSQLHelpers::setupTable( $smw_conccache,
966 - array( 's_id' => $dbtypes['p'] . ' NOT NULL',
967 - 'o_id' => $dbtypes['p'] . ' NOT NULL' ), $db, $reportTo );
968 - SMWSQLHelpers::setupIndex( $smw_conccache, array( 'o_id' ), $db );
969 - // set up concept descriptions
970 - SMWSQLHelpers::setupTable( $smw_conc2,
971 - array( 's_id' => $dbtypes['p'] . ' NOT NULL' .
972 - ( $wgDBtype == 'postgres' ? ' PRIMARY KEY':' KEY' ),
973 - 'concept_txt' => $dbtypes['l'],
974 - 'concept_docu' => $dbtypes['l'],
975 - 'concept_features' => $dbtypes['i'],
976 - 'concept_size' => $dbtypes['i'],
977 - 'concept_depth' => $dbtypes['i'],
978 - 'cache_date' => $dbtypes['j'],
979 - 'cache_count' => $dbtypes['j'] ), $db, $reportTo );
980 - SMWSQLHelpers::setupIndex( $smw_conc2, array( 's_id' ), $db );
 976+ // Set up concept cache: member elements (s)->concepts (o)
 977+ SMWSQLHelpers::setupTable(
 978+ 'smw_conccache',
 979+ array(
 980+ 's_id' => $dbtypes['p'] . ' NOT NULL',
 981+ 'o_id' => $dbtypes['p'] . ' NOT NULL'
 982+ ),
 983+ $db,
 984+ $reportTo
 985+ );
 986+
 987+ SMWSQLHelpers::setupIndex( 'smw_conccache', array( 'o_id' ), $db );
 988+
 989+ // Set up concept descriptions.
 990+ SMWSQLHelpers::setupTable(
 991+ 'smw_conc2',
 992+ array(
 993+ 's_id' => $dbtypes['p'] . ' NOT NULL' . ( $wgDBtype == 'postgres' ? ' PRIMARY KEY' : ' KEY' ),
 994+ 'concept_txt' => $dbtypes['l'],
 995+ 'concept_docu' => $dbtypes['l'],
 996+ 'concept_features' => $dbtypes['i'],
 997+ 'concept_size' => $dbtypes['i'],
 998+ 'concept_depth' => $dbtypes['i'],
 999+ 'cache_date' => $dbtypes['j'],
 1000+ 'cache_count' => $dbtypes['j']
 1001+ ),
 1002+ $db,
 1003+ $reportTo
 1004+ );
 1005+
 1006+ SMWSQLHelpers::setupIndex( 'smw_conc2', array( 's_id' ), $db );
9811007
9821008 // Set up all property tables as defined:
983 - foreach ( SMWSQLStoreLight::getPropertyTables() as $proptable ) {
 1009+ $this->setupPropertyTables( $dbtypes, $db, $reportTo );
 1010+
 1011+ $this->reportProgress( "Database initialised successfully.\n\n", $verbose );
 1012+ }
 1013+
 1014+ /**
 1015+ * Sets up the property tables.
 1016+ *
 1017+ * @param array $dbtypes
 1018+ * @param $db
 1019+ * @param $reportTo SMWSQLStore2 or null
 1020+ */
 1021+ protected function setupPropertyTables( array $dbtypes, $db, $reportTo ) {
 1022+ $addedCustomTypeSignatures = false;
 1023+
 1024+ foreach ( self::getPropertyTables() as $proptable ) {
9841025 if ( $proptable->idsubject ) {
9851026 $fieldarray = array( 's_id' => $dbtypes['p'] . ' NOT NULL' );
9861027 $indexes = array( 's_id' );
@@ -987,19 +1028,30 @@
9881029 $fieldarray = array( 's_title' => $dbtypes['t'] . ' NOT NULL', 's_namespace' => $dbtypes['n'] . ' NOT NULL' );
9891030 $indexes = array( 's_title,s_namespace' );
9901031 }
991 - if ( $proptable->fixedproperty == false ) {
 1032+
 1033+ if ( !$proptable->fixedproperty ) {
9921034 $fieldarray['p_id'] = $dbtypes['p'] . ' NOT NULL';
9931035 $indexes[] = 'p_id';
9941036 }
 1037+
9951038 foreach ( $proptable->objectfields as $fieldname => $typeid ) {
996 - $fieldarray[$fieldname] = $dbtypes[$typeid];
 1039+ // If the type signature is not recognized and the custom signatures have not been added, add them.
 1040+ if ( !$addedCustomTypeSignatures && !array_key_exists( $typeid, $dbtypes ) ) {
 1041+ wfRunHooks( 'SMWCustomSQLStoreFieldType', array( &$dbtypes ) );
 1042+ $addedCustomTypeSignatures = true;
 1043+ }
 1044+
 1045+ // Only add the type when the signature was recognized, otherwise ignore it silently.
 1046+ if ( array_key_exists( $typeid, $dbtypes ) ) {
 1047+ $fieldarray[$fieldname] = $dbtypes[$typeid];
 1048+ }
9971049 }
 1050+
9981051 $indexes = array_merge( $indexes, $proptable->indexes );
 1052+
9991053 SMWSQLHelpers::setupTable( $proptable->name, $fieldarray, $db, $reportTo );
1000 - SMWSQLHelpers::setupIndex( $proptable->name, $indexes, $db );
1001 - }
1002 -
1003 - $this->reportProgress( "Database initialised successfully.\n\n", $verbose );
 1054+ SMWSQLHelpers::setupIndex( $proptable->name, $indexes, $db );
 1055+ }
10041056 }
10051057
10061058 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r66680Changes for 1.5.1 - improved table and index creation code in the SQL store. ...jeroendedauw04:33, 20 May 2010

Status & tagging log