List:Commits« Previous MessageNext Message »
From:U-ROWVWADEjas Date:May 6 2008 5:52pm
Subject:bk commit into 6.0 tree (jas:1.2669)
View as plain text  
Below is the list of changes that have just been committed into a local
6.0 repository of jas.  When jas does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-05-06 11:52:21-04:00, jas@rowvwade. +8 -0
  Got limit optimization working for disk indexes.

  storage/falcon/IndexRootPage.cpp@stripped, 2008-05-06 11:52:05-04:00, jas@rowvwade. +8 -0
    Got limit optimization working for disk indexes.

  storage/falcon/IndexRootPage.h@stripped, 2008-05-06 11:52:06-04:00, jas@rowvwade. +1 -0
    Got limit optimization working for disk indexes.

  storage/falcon/IndexWalker.cpp@stripped, 2008-05-06 11:52:06-04:00, jas@rowvwade. +53 -0
    Got limit optimization working for disk indexes.

  storage/falcon/IndexWalker.h@stripped, 2008-05-06 11:52:06-04:00, jas@rowvwade. +5 -0
    Got limit optimization working for disk indexes.

  storage/falcon/WalkIndex.cpp@stripped, 2008-05-06 11:52:07-04:00, jas@rowvwade. +50 -4
    Got limit optimization working for disk indexes.

  storage/falcon/WalkIndex.h@stripped, 2008-05-06 11:52:07-04:00, jas@rowvwade. +3 -2
    Got limit optimization working for disk indexes.

  storage/falcon/ha_falcon.cpp@stripped, 2008-05-06 11:52:07-04:00, jas@rowvwade. +25 -13
    Got limit optimization working for disk indexes.

  storage/falcon/ha_falcon.h@stripped, 2008-05-06 11:52:08-04:00, jas@rowvwade. +1 -2
    Got limit optimization working for disk indexes.

diff -Nrup a/storage/falcon/IndexRootPage.cpp b/storage/falcon/IndexRootPage.cpp
--- a/storage/falcon/IndexRootPage.cpp	2008-05-02 18:09:09 -04:00
+++ b/storage/falcon/IndexRootPage.cpp	2008-05-06 11:52:05 -04:00
@@ -1199,3 +1199,11 @@ void IndexRootPage::positionIndex(Dbb* d
 	walkIndex->setNodes(page->nextPage, page->length - ((UCHAR*) node.node -
(UCHAR*) page->nodes), node.node);
 	bdb->release(REL_HISTORY);
 }
+
+void IndexRootPage::repositionIndex(Dbb* dbb, int indexId, WalkIndex* walkIndex)
+{
+	Bdb *bdb = dbb->fetchPage(walkIndex->nextPage, PAGE_btree, Shared);
+	IndexPage *page = (IndexPage*) bdb->buffer;
+	walkIndex->setNodes(page->nextPage, page->length - OFFSET(IndexPage*, nodes),
page->nodes);
+	bdb->release(REL_HISTORY);
+}
diff -Nrup a/storage/falcon/IndexRootPage.h b/storage/falcon/IndexRootPage.h
--- a/storage/falcon/IndexRootPage.h	2008-05-02 18:09:09 -04:00
+++ b/storage/falcon/IndexRootPage.h	2008-05-06 11:52:06 -04:00
@@ -47,6 +47,7 @@ public:
 									AddNodeResult addResult, IndexKey *indexKey, int recordNumber);
 	static void		scanIndex (Dbb *dbb, int32 indexId, int32 rootPage, IndexKey *low, IndexKey
*high, int searchFlags, TransId transId, Bitmap *bitmap);
 	static void		positionIndex(Dbb* dbb, int indexId, int32 rootPage, WalkIndex* walkIndex);
+	static void		repositionIndex(Dbb* dbb, int indexId, WalkIndex* walkIndex);
 	static Bdb*		findRoot (Dbb *dbb, int32 indexId, int32 rootPage, LockType lockType,
TransId transId);
 	static Bdb*		findLeaf (Dbb *dbb, int32 indexId, int32 rootPage, IndexKey *key, LockType
lockType, TransId transId);
 	static Bdb*		findInsertionLeaf (Dbb *dbb, int32 indexId, IndexKey *key, int32
recordNumber, TransId transId);
diff -Nrup a/storage/falcon/IndexWalker.cpp b/storage/falcon/IndexWalker.cpp
--- a/storage/falcon/IndexWalker.cpp	2008-05-02 18:09:10 -04:00
+++ b/storage/falcon/IndexWalker.cpp	2008-05-06 11:52:06 -04:00
@@ -15,12 +15,18 @@
 
 #include "Engine.h"
 #include "IndexWalker.h"
+#include "Record.h"
+#include "Table.h"
+#include "SQLError.h"
 
 IndexWalker::IndexWalker(Index *idx, Transaction *trans, int flags)
 {
 	index = idx;
+	table = index->table;
 	transaction = trans;
 	searchFlags = flags;
+	currentRecord = NULL;
+	first = true;
 }
 
 IndexWalker::~IndexWalker(void)
@@ -30,4 +36,51 @@ IndexWalker::~IndexWalker(void)
 Record* IndexWalker::getNext(bool lockForUpdate)
 {
 	return NULL;
+}
+
+Record* IndexWalker::getValidatedRecord(int32 recordId, bool lockForUpdate)
+{
+	// Fetch record.  If it doesn't exist, that's ok.
+	
+	Record *candidate = table->fetch(recordId);
+
+	if (!candidate)
+		return NULL;
+	
+	// Get the correct version.  If this is select for update, get a lock record
+			
+	Record *record = (lockForUpdate) 
+				    ? table->fetchForUpdate(transaction, candidate, true)
+				    : candidate->fetchVersion(transaction);
+	
+	if (!record)
+		{
+		if (!lockForUpdate)
+			candidate->release();
+		
+		return NULL;
+		}
+	
+	// If we have a different record version, release the original
+	
+	if (!lockForUpdate && candidate != record)
+		{
+		record->addRef();
+		candidate->release();
+		}
+	
+	// Compute record key and compare against index key.  If there' different, punt
+	
+	IndexKey recordKey;
+	index->makeKey(record, &recordKey);
+	
+	if (recordKey.keyLength != key.keyLength ||
+		memcmp(recordKey.key, key.key, key.keyLength) != 0)
+		{
+		record->release();
+		
+		return NULL;
+		}
+	
+	return record;
 }
diff -Nrup a/storage/falcon/IndexWalker.h b/storage/falcon/IndexWalker.h
--- a/storage/falcon/IndexWalker.h	2008-05-02 18:09:10 -04:00
+++ b/storage/falcon/IndexWalker.h	2008-05-06 11:52:06 -04:00
@@ -21,6 +21,7 @@
 class Index;
 class Transaction;
 class Record;
+class Table;
 
 class IndexWalker
 {
@@ -29,11 +30,15 @@ public:
 	~IndexWalker(void);
 	
 	virtual Record*		getNext(bool lockForUpdate);
+	Record*				getValidatedRecord(int32 recordId, bool lockForUpdate);
 	
 	Index		*index;
 	Transaction	*transaction;
 	IndexKey	key;
+	Record		*currentRecord;
+	Table		*table;
 	int			searchFlags;
+	bool		first;
 };
 
 #endif
diff -Nrup a/storage/falcon/WalkIndex.cpp b/storage/falcon/WalkIndex.cpp
--- a/storage/falcon/WalkIndex.cpp	2008-05-02 18:09:13 -04:00
+++ b/storage/falcon/WalkIndex.cpp	2008-05-06 11:52:07 -04:00
@@ -22,6 +22,7 @@
 #include "Dbb.h"
 #include "WalkIndex.h"
 #include "WalkIndex.h"
+#include "IndexRootPage.h"
 
 #ifdef _DEBUG
 #undef THIS_FILE
@@ -41,7 +42,6 @@ WalkIndex::WalkIndex(Index *index, Trans
 		upperBound.setKey(upper);
 	
 	nodes = new UCHAR[transaction->database->dbb->pageSize];
-	record = NULL;
 }
 
 WalkIndex::~WalkIndex(void)
@@ -49,14 +49,60 @@ WalkIndex::~WalkIndex(void)
 	delete [] nodes;
 }
 
-void WalkIndex::setNodes(int32 nextPage, int length, Btn* stuff)
+void WalkIndex::setNodes(int32 nextIndexPage, int length, Btn* stuff)
 {
 	memcpy(nodes, stuff, length);
 	endNodes = (Btn*) (nodes + length);
-	node.parseNode(stuff, endNodes);
+	node.parseNode((Btn*) nodes, endNodes);
+	nextPage = nextIndexPage;
 }
 
 Record* WalkIndex::getNext(bool lockForUpdate)
 {
-	return NULL;
+	for (;;)
+		{
+		int32 recordNumber = getNextNode();
+		
+		if (recordNumber < 0)
+			{
+			currentRecord = NULL;
+			
+			return NULL;
+			}
+		
+		if ( (currentRecord = getValidatedRecord(recordNumber, lockForUpdate)) )
+			return currentRecord;
+		}
+}
+
+int32 WalkIndex::getNextNode(void)
+{
+	for (;; first = true)
+		{
+		if (first)
+			{
+			first = false;
+			int32 recordNumber = node.getNumber();
+			
+			if (recordNumber >= 0)
+				return recordNumber;
+			}
+			
+		node.getNext(endNodes);
+		
+		if (node.node < endNodes)
+			{
+			int32 recordNumber = node.getNumber();
+			node.expandKey(&key);
+			
+			if (recordNumber >= 0)
+				return recordNumber;
+			}
+		
+		if (nextPage == 0)
+			return -1;
+			
+		IndexRootPage::repositionIndex(index->dbb, index->indexId, this);
+		}
+	
 }
diff -Nrup a/storage/falcon/WalkIndex.h b/storage/falcon/WalkIndex.h
--- a/storage/falcon/WalkIndex.h	2008-05-02 18:09:14 -04:00
+++ b/storage/falcon/WalkIndex.h	2008-05-06 11:52:07 -04:00
@@ -29,12 +29,13 @@ public:
 	WalkIndex(Index *index, Transaction *transaction, int flags, IndexKey *lower, IndexKey
*upper);
 	virtual ~WalkIndex(void);
 	
-	void			setNodes(int32 nextPage, int length, Btn* stuff);
 	virtual Record* getNext(bool lockForUpdate);
 	
+	int32			getNextNode(void);
+	void			setNodes(int32 nextPage, int length, Btn* stuff);
+	
 	IndexKey	lowerBound;
 	IndexKey	upperBound;
-	Record		*record;
 	UCHAR		*nodes;
 	IndexNode	node;
 	Btn			*endNodes;
diff -Nrup a/storage/falcon/ha_falcon.cpp b/storage/falcon/ha_falcon.cpp
--- a/storage/falcon/ha_falcon.cpp	2008-05-05 13:53:52 -04:00
+++ b/storage/falcon/ha_falcon.cpp	2008-05-06 11:52:07 -04:00
@@ -109,8 +109,8 @@ static const ulonglong default_table_fla
 												| HA_CAN_GEOMETRY
 												//| HA_AUTO_PART_KEY
 												| HA_ONLINE_ALTER
-												| HA_BINLOG_ROW_CAPABLE);
-//												| HA_CAN_READ_ORDER_IF_LIMIT);
+												| HA_BINLOG_ROW_CAPABLE
+												| HA_CAN_READ_ORDER_IF_LIMIT);
 
 static struct st_mysql_show_var falconStatus[] =
 {
@@ -221,11 +221,12 @@ int StorageInterface::falcon_init(void *
 
 	if (error)
 		{
-			// Cleanup after error
-			delete storageHandler;
-			storageHandler = 0;
-			DBUG_RETURN(1);
+		// Cleanup after error
+		delete storageHandler;
+		storageHandler = 0;
+		DBUG_RETURN(1);
 		}
+		
 	DBUG_RETURN(0);
 }
 
@@ -384,7 +385,7 @@ typedef longlong      dec2;
 //////////////////////////////////////////////////////////////////////
 
 StorageInterface::StorageInterface(handlerton *hton, st_table_share *table_arg)
-  : handler(hton, table_arg), ordered_index_reads(false)
+  : handler(hton, table_arg)
 {
 	ref_length = sizeof(lastRecord);
 	stats.records = 1000;
@@ -401,7 +402,7 @@ StorageInterface::StorageInterface(handl
 	freeBlobs = NULL;
 	errorText = NULL;
 	fieldMap = NULL;
-	indexOrder = true;
+	indexOrder = false;
 	
 	if (table_arg)
 		{
@@ -737,11 +738,10 @@ ulonglong StorageInterface::table_flags(
 ulong StorageInterface::index_flags(uint idx, uint part, bool all_parts) const
 {
 	DBUG_ENTER("StorageInterface::index_flags");
-	ulong flags = HA_READ_RANGE | ((indexOrder) ? 0 : HA_KEY_SCAN_NOT_ROR);
+	ulong flags = HA_READ_RANGE | ((indexOrder) ? HA_READ_ORDER : HA_KEY_SCAN_NOT_ROR);
 	
 	DBUG_RETURN(flags);
-	DBUG_RETURN(HA_READ_RANGE | HA_KEY_SCAN_NOT_ROR |
-			(ordered_index_reads ? HA_READ_ORDER : 0));
+	//DBUG_RETURN(HA_READ_RANGE | HA_KEY_SCAN_NOT_ROR | (indexOrder ? HA_READ_ORDER : 0));
 }
 
 
@@ -1834,6 +1834,16 @@ int StorageInterface::start_stmt(THD *th
 	DBUG_RETURN(0);
 }
 
+int StorageInterface::reset()
+{
+	DBUG_ENTER("StorageInterface::start_stmt");
+	indexOrder = false;
+
+	DBUG_RETURN(0);
+}
+
+ 
+ 
 int StorageInterface::external_lock(THD *thd, int lock_type)
 {
 	DBUG_ENTER("StorageInterface::external_lock");
@@ -2739,6 +2749,7 @@ void StorageInterface::decodeRecord(ucha
 int StorageInterface::extra(ha_extra_function operation)
 {
 	DBUG_ENTER("StorageInterface::extra");
+	
 	if (operation == HA_EXTRA_ORDERBY_LIMIT)
 		{
 		// SQL Layer informs us that it is considering an ORDER BY .. LIMIT
@@ -2749,7 +2760,7 @@ int StorageInterface::extra(ha_extra_fun
 		//  2. If doing #1, every index/range scan must return records in
 		//     index order.
 
-		ordered_index_reads= TRUE;
+		indexOrder = true;
 		}
 
 	if (operation == HA_EXTRA_NO_ORDERBY_LIMIT)
@@ -2758,7 +2769,8 @@ int StorageInterface::extra(ha_extra_fun
 		// ORDER BY ... LIMIT. This could happen for a number of reasons,
 		// but the result is that we don't have to return records in index
 		// order.
-		ordered_index_reads= FALSE;
+		
+		indexOrder = false;
 		}
 
 	DBUG_RETURN(0);
diff -Nrup a/storage/falcon/ha_falcon.h b/storage/falcon/ha_falcon.h
--- a/storage/falcon/ha_falcon.h	2008-05-05 11:48:34 -04:00
+++ b/storage/falcon/ha_falcon.h	2008-05-06 11:52:08 -04:00
@@ -96,7 +96,7 @@ public:
 	virtual int		optimize(THD* thd, HA_CHECK_OPT* check_opt);
 	virtual int		check(THD* thd, HA_CHECK_OPT* check_opt);
 	virtual int		repair(THD* thd, HA_CHECK_OPT* check_opt);
-	virtual int		reset() { ordered_index_reads= false; return 0; }
+	virtual int		reset();
 
 	virtual int		check_if_supported_alter(TABLE *altered_table, HA_CREATE_INFO *create_info,
HA_ALTER_FLAGS *alter_flags, uint table_changes);
 	virtual int		alter_table_phase1(THD* thd, TABLE* altered_table, HA_CREATE_INFO*
create_info, HA_ALTER_INFO* alter_info, HA_ALTER_FLAGS* alter_flags);
@@ -191,7 +191,6 @@ public:
 	key_range			endKey;
 	uint64				insertCount;
 	ulonglong			tableFlags;
-	bool			ordered_index_reads;
 };
 
 class NfsPluginHandler
Thread
bk commit into 6.0 tree (jas:1.2669)U-ROWVWADEjas6 May