Skip to content

Commit

Permalink
Improve style
Browse files Browse the repository at this point in the history
This commit aims to improve style by changing some of the variable
names, code alignments and comments.
  • Loading branch information
onderkalaci committed Jan 23, 2015
1 parent 2a49c31 commit 863f3ec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
37 changes: 23 additions & 14 deletions prune_shard_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@


/*
* OperatorTypeCache is used for caching base operator types for given typeId,
* OperatorIdCache is used for caching operator identifiers for given typeId,
* accessMethodId and strategyNumber. It is initialized to empty list as
* there are no items in the cache.
*/
static List *OperatorTypeCache = NIL;
static List *OperatorIdCache = NIL;


/* local function forward declarations */
static Oid GetOperatorByType(Oid typeId, Oid accessMethodId, int16 strategyNumber);
static Oid LookupOperatorByType(Oid typeId, Oid accessMethodId, int16 strategyNumber);
static Oid GetOperatorByType(Oid typeId, Oid accessMethodId, int16 strategyNumber);
static bool SimpleOpExpression(Expr *clause);
static Node * HashableClauseMutator(Node *originalNode, Var *partitionColumn);
static bool OpExpressionContainsColumn(OpExpr *operatorExpression, Var *partitionColumn);
Expand Down Expand Up @@ -250,21 +250,22 @@ MakeOpExpression(Var *variable, int16 strategyNumber)

/*
* LookupOperatorByType is a wrapper around GetOperatorByType that uses a cache
* to avoid multiple lookups of operators by their types.
* to avoid multiple lookups of operators within a single session by their types.
*/
static Oid
LookupOperatorByType(Oid typeId, Oid accessMethodId, int16 strategyNumber)
{
OperatorTypeCacheEntry *matchingCacheEntry = NULL;
OperatorIdCacheEntry *matchingCacheEntry = NULL;
ListCell *cacheEntryCell = NULL;

/* search the cache */
foreach(cacheEntryCell, OperatorTypeCache)
foreach(cacheEntryCell, OperatorIdCache)
{
OperatorTypeCacheEntry *cacheEntry = lfirst(cacheEntryCell);
OperatorIdCacheEntry *cacheEntry = lfirst(cacheEntryCell);

if (cacheEntry->typeId == typeId && cacheEntry->accessMethodId == accessMethodId
&& cacheEntry->strategyNumber == strategyNumber)
if ((cacheEntry->typeId == typeId) &&
(cacheEntry->accessMethodId == accessMethodId) &&
(cacheEntry->strategyNumber == strategyNumber))
{
matchingCacheEntry = cacheEntry;
break;
Expand All @@ -274,17 +275,25 @@ LookupOperatorByType(Oid typeId, Oid accessMethodId, int16 strategyNumber)
/* if not found in the cache, call GetOperatorByType and put the result in cache */
if (matchingCacheEntry == NULL)
{
Oid operatorId = GetOperatorByType(typeId, accessMethodId, strategyNumber);
MemoryContext oldContext = MemoryContextSwitchTo(CacheMemoryContext);
Oid operatorId;
MemoryContext oldContext;

matchingCacheEntry = palloc0(sizeof(OperatorTypeCacheEntry));
operatorId = GetOperatorByType(typeId, accessMethodId, strategyNumber);
if (operatorId == InvalidOid)
{
/* if operatorId is invalid, return and do not cache its value */
return operatorId;
}

oldContext = MemoryContextSwitchTo(CacheMemoryContext);

matchingCacheEntry = palloc0(sizeof(OperatorIdCacheEntry));
matchingCacheEntry->typeId = typeId;
matchingCacheEntry->accessMethodId = accessMethodId;
matchingCacheEntry->strategyNumber = strategyNumber;

matchingCacheEntry->operatorId = operatorId;

OperatorTypeCache = lappend(OperatorTypeCache, matchingCacheEntry);
OperatorIdCache = lappend(OperatorIdCache, matchingCacheEntry);

MemoryContextSwitchTo(oldContext);
}
Expand Down
10 changes: 3 additions & 7 deletions prune_shard_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,15 @@
#define RESERVED_HASHED_COLUMN_ID MaxAttrNumber


/*
* OperatorTypeCacheEntry contains the information for a cache entry in
* operator type cache.
*/
typedef struct OperatorTypeCacheEntry
/* OperatorIdCacheEntry contains information for each element in OperatorIdCache */
typedef struct OperatorIdCacheEntry
{
/* cache key consists of typeId, accessMethodId and strategyNumber */
Oid typeId;
Oid accessMethodId;
int16 strategyNumber;

Oid operatorId;
} OperatorTypeCacheEntry;
} OperatorIdCacheEntry;


/* function declarations for shard pruning */
Expand Down

0 comments on commit 863f3ec

Please sign in to comment.