mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-31 00:03:57 -04:00 
			
		
		
		
	Change
typedef struct {} WordEntryPos;
to
typedef uint16 WordEntryPos
according to http://www.pgsql.ru/db/mw/msg.html?mid=2035188
Require re-fill all tsvector fields and reindex tsvector indexes.
			
			
This commit is contained in:
		
							parent
							
								
									4405e74355
								
							
						
					
					
						commit
						fe30edbab8
					
				| @ -396,7 +396,7 @@ checkclass_str(CHKVAL * chkval, WordEntry * val, ITEM * item) | |||||||
| 
 | 
 | ||||||
| 	while (len--) | 	while (len--) | ||||||
| 	{ | 	{ | ||||||
| 		if (item->weight & (1 << ptr->weight)) | 		if (item->weight & (1 << WEP_GETWEIGHT(*ptr))) | ||||||
| 			return true; | 			return true; | ||||||
| 		ptr++; | 		ptr++; | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -39,7 +39,7 @@ Datum		get_covers(PG_FUNCTION_ARGS); | |||||||
| 
 | 
 | ||||||
| static float weights[] = {0.1, 0.2, 0.4, 1.0}; | static float weights[] = {0.1, 0.2, 0.4, 1.0}; | ||||||
| 
 | 
 | ||||||
| #define wpos(wep)	( w[ ((WordEntryPos*)(wep))->weight ] ) | #define wpos(wep)	( w[ WEP_GETWEIGHT(wep) ] ) | ||||||
| 
 | 
 | ||||||
| #define DEF_NORM_METHOD 0 | #define DEF_NORM_METHOD 0 | ||||||
| 
 | 
 | ||||||
| @ -113,8 +113,8 @@ find_wordentry(tsvector * t, QUERYTYPE * q, ITEM * item) | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static WordEntryPos POSNULL[] = { | static WordEntryPos POSNULL[] = { | ||||||
| 	{0, 0}, | 	0, | ||||||
| 	{0, MAXENTRYPOS - 1} | 	0 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| static float | static float | ||||||
| @ -136,6 +136,7 @@ calc_rank_and(float *w, tsvector * t, QUERYTYPE * q) | |||||||
| 
 | 
 | ||||||
| 	memset(pos, 0, sizeof(uint16 **) * q->size); | 	memset(pos, 0, sizeof(uint16 **) * q->size); | ||||||
| 	*(uint16 *) POSNULL = lengthof(POSNULL) - 1; | 	*(uint16 *) POSNULL = lengthof(POSNULL) - 1; | ||||||
|  | 	WEP_SETPOS(POSNULL[1], MAXENTRYPOS-1);  | ||||||
| 
 | 
 | ||||||
| 	for (i = 0; i < q->size; i++) | 	for (i = 0; i < q->size; i++) | ||||||
| 	{ | 	{ | ||||||
| @ -165,14 +166,14 @@ calc_rank_and(float *w, tsvector * t, QUERYTYPE * q) | |||||||
| 			{ | 			{ | ||||||
| 				for (p = 0; p < lenct; p++) | 				for (p = 0; p < lenct; p++) | ||||||
| 				{ | 				{ | ||||||
| 					dist = Abs(post[l].pos - ct[p].pos); | 					dist = Abs((int)WEP_GETPOS(post[l]) - (int)WEP_GETPOS(ct[p])); | ||||||
| 					if (dist || (dist == 0 && (pos[i] == (uint16 *) POSNULL || pos[k] == (uint16 *) POSNULL))) | 					if (dist || (dist == 0 && (pos[i] == (uint16 *) POSNULL || pos[k] == (uint16 *) POSNULL))) | ||||||
| 					{ | 					{ | ||||||
| 						float		curw; | 						float		curw; | ||||||
| 
 | 
 | ||||||
| 						if (!dist) | 						if (!dist) | ||||||
| 							dist = MAXENTRYPOS; | 							dist = MAXENTRYPOS; | ||||||
| 						curw = sqrt(wpos(&(post[l])) * wpos(&(ct[p])) * word_distance(dist)); | 						curw = sqrt(wpos(post[l]) * wpos(ct[p]) * word_distance(dist)); | ||||||
| 						res = (res < 0) ? curw : 1.0 - (1.0 - res) * (1.0 - curw); | 						res = (res < 0) ? curw : 1.0 - (1.0 - res) * (1.0 - curw); | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| @ -219,9 +220,9 @@ calc_rank_or(float *w, tsvector * t, QUERYTYPE * q) | |||||||
| 		for (j = 0; j < dimt; j++) | 		for (j = 0; j < dimt; j++) | ||||||
| 		{ | 		{ | ||||||
| 			if (res < 0) | 			if (res < 0) | ||||||
| 				res = wpos(&(post[j])); | 				res = wpos(post[j]); | ||||||
| 			else | 			else | ||||||
| 				res = 1.0 - (1.0 - res) * (1.0 - wpos(&(post[j]))); | 				res = 1.0 - (1.0 - res) * (1.0 - wpos(post[j])); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return res; | 	return res; | ||||||
| @ -497,7 +498,7 @@ get_docrep(tsvector * txt, QUERYTYPE * query, int *doclen) | |||||||
| 		for (j = 0; j < dimt; j++) | 		for (j = 0; j < dimt; j++) | ||||||
| 		{ | 		{ | ||||||
| 			doc[cur].item = &(item[i]); | 			doc[cur].item = &(item[i]); | ||||||
| 			doc[cur].pos = post[j].pos; | 			doc[cur].pos = WEP_GETPOS(post[j]); | ||||||
| 			cur++; | 			cur++; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @ -656,7 +657,7 @@ get_covers(PG_FUNCTION_ARGS) | |||||||
| 		{ | 		{ | ||||||
| 			dw[cur].w = STRPTR(txt) + pptr[i].pos; | 			dw[cur].w = STRPTR(txt) + pptr[i].pos; | ||||||
| 			dw[cur].len = pptr[i].len; | 			dw[cur].len = pptr[i].len; | ||||||
| 			dw[cur].pos = posdata[j].pos; | 			dw[cur].pos = WEP_GETPOS(posdata[j]); | ||||||
| 			cur++; | 			cur++; | ||||||
| 		} | 		} | ||||||
| 		len += (pptr[i].len + 1) * (int) POSDATALEN(txt, &(pptr[i])); | 		len += (pptr[i].len + 1) * (int) POSDATALEN(txt, &(pptr[i])); | ||||||
|  | |||||||
| @ -42,7 +42,7 @@ check_weight(tsvector * txt, WordEntry * wptr, int8 weight) | |||||||
| 
 | 
 | ||||||
| 	while (len--) | 	while (len--) | ||||||
| 	{ | 	{ | ||||||
| 		if (weight & (1 << ptr->weight)) | 		if (weight & (1 << WEP_GETWEIGHT(*ptr))) | ||||||
| 			num++; | 			num++; | ||||||
| 		ptr++; | 		ptr++; | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -50,9 +50,9 @@ Datum		tsvector_length(PG_FUNCTION_ARGS); | |||||||
| static int | static int | ||||||
| comparePos(const void *a, const void *b) | comparePos(const void *a, const void *b) | ||||||
| { | { | ||||||
| 	if (((WordEntryPos *) a)->pos == ((WordEntryPos *) b)->pos) | 	if (WEP_GETPOS(*(WordEntryPos *) a) == WEP_GETPOS(*(WordEntryPos *) b)) | ||||||
| 		return 1; | 		return 1; | ||||||
| 	return (((WordEntryPos *) a)->pos > ((WordEntryPos *) b)->pos) ? 1 : -1; | 	return (WEP_GETPOS(*(WordEntryPos *) a)> WEP_GETPOS(*(WordEntryPos *) b)) ? 1 : -1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static int | static int | ||||||
| @ -70,16 +70,15 @@ uniquePos(WordEntryPos * a, int4 l) | |||||||
| 	ptr = a + 1; | 	ptr = a + 1; | ||||||
| 	while (ptr - a < l) | 	while (ptr - a < l) | ||||||
| 	{ | 	{ | ||||||
| 		if (ptr->pos != res->pos) | 		if (WEP_GETPOS(*ptr) != WEP_GETPOS(*res)) | ||||||
| 		{ | 		{ | ||||||
| 			res++; | 			res++; | ||||||
| 			res->pos = ptr->pos; | 			*res = *ptr; | ||||||
| 			res->weight = ptr->weight; | 			if (res - a >= MAXNUMPOS - 1 || WEP_GETPOS(*res) == MAXENTRYPOS - 1) | ||||||
| 			if (res - a >= MAXNUMPOS - 1 || res->pos == MAXENTRYPOS - 1) |  | ||||||
| 				break; | 				break; | ||||||
| 		} | 		} | ||||||
| 		else if (ptr->weight > res->weight) | 		else if (WEP_GETWEIGHT(*ptr) > WEP_GETWEIGHT(*res)) | ||||||
| 			res->weight = ptr->weight; | 			WEP_SETWEIGHT(*res, WEP_GETWEIGHT(*ptr)); | ||||||
| 		ptr++; | 		ptr++; | ||||||
| 	} | 	} | ||||||
| 	return res + 1 - a; | 	return res + 1 - a; | ||||||
| @ -324,12 +323,12 @@ gettoken_tsvector(TI_IN_STATE * state) | |||||||
| 					state->pos = (WordEntryPos *) repalloc(state->pos, sizeof(WordEntryPos) * state->alen); | 					state->pos = (WordEntryPos *) repalloc(state->pos, sizeof(WordEntryPos) * state->alen); | ||||||
| 				} | 				} | ||||||
| 				(*(uint16 *) (state->pos))++; | 				(*(uint16 *) (state->pos))++; | ||||||
| 				state->pos[*(uint16 *) (state->pos)].pos = LIMITPOS(atoi(state->prsbuf)); | 				WEP_SETPOS(state->pos[*(uint16 *) (state->pos)], LIMITPOS(atoi(state->prsbuf))); | ||||||
| 				if (state->pos[*(uint16 *) (state->pos)].pos == 0) | 				if (WEP_GETPOS(state->pos[*(uint16 *) (state->pos)]) == 0) | ||||||
| 					ereport(ERROR, | 					ereport(ERROR, | ||||||
| 							(errcode(ERRCODE_SYNTAX_ERROR), | 							(errcode(ERRCODE_SYNTAX_ERROR), | ||||||
| 							 errmsg("wrong position info"))); | 							 errmsg("wrong position info"))); | ||||||
| 				state->pos[*(uint16 *) (state->pos)].weight = 0; | 				WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 0 ); | ||||||
| 				state->state = WAITPOSDELIM; | 				state->state = WAITPOSDELIM; | ||||||
| 			} | 			} | ||||||
| 			else | 			else | ||||||
| @ -343,35 +342,35 @@ gettoken_tsvector(TI_IN_STATE * state) | |||||||
| 				state->state = INPOSINFO; | 				state->state = INPOSINFO; | ||||||
| 			else if (tolower(*(state->prsbuf)) == 'a' || *(state->prsbuf) == '*') | 			else if (tolower(*(state->prsbuf)) == 'a' || *(state->prsbuf) == '*') | ||||||
| 			{ | 			{ | ||||||
| 				if (state->pos[*(uint16 *) (state->pos)].weight) | 				if ( WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]) ) | ||||||
| 					ereport(ERROR, | 					ereport(ERROR, | ||||||
| 							(errcode(ERRCODE_SYNTAX_ERROR), | 							(errcode(ERRCODE_SYNTAX_ERROR), | ||||||
| 							 errmsg("syntax error"))); | 							 errmsg("syntax error"))); | ||||||
| 				state->pos[*(uint16 *) (state->pos)].weight = 3; | 				WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 3 ); | ||||||
| 			} | 			} | ||||||
| 			else if (tolower(*(state->prsbuf)) == 'b') | 			else if (tolower(*(state->prsbuf)) == 'b') | ||||||
| 			{ | 			{ | ||||||
| 				if (state->pos[*(uint16 *) (state->pos)].weight) | 				if ( WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]) ) | ||||||
| 					ereport(ERROR, | 					ereport(ERROR, | ||||||
| 							(errcode(ERRCODE_SYNTAX_ERROR), | 							(errcode(ERRCODE_SYNTAX_ERROR), | ||||||
| 							 errmsg("syntax error"))); | 							 errmsg("syntax error"))); | ||||||
| 				state->pos[*(uint16 *) (state->pos)].weight = 2; | 				WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 2 ); | ||||||
| 			} | 			} | ||||||
| 			else if (tolower(*(state->prsbuf)) == 'c') | 			else if (tolower(*(state->prsbuf)) == 'c') | ||||||
| 			{ | 			{ | ||||||
| 				if (state->pos[*(uint16 *) (state->pos)].weight) | 				if ( WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]) ) | ||||||
| 					ereport(ERROR, | 					ereport(ERROR, | ||||||
| 							(errcode(ERRCODE_SYNTAX_ERROR), | 							(errcode(ERRCODE_SYNTAX_ERROR), | ||||||
| 							 errmsg("syntax error"))); | 							 errmsg("syntax error"))); | ||||||
| 				state->pos[*(uint16 *) (state->pos)].weight = 1; | 				WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 1 ); | ||||||
| 			} | 			} | ||||||
| 			else if (tolower(*(state->prsbuf)) == 'd') | 			else if (tolower(*(state->prsbuf)) == 'd') | ||||||
| 			{ | 			{ | ||||||
| 				if (state->pos[*(uint16 *) (state->pos)].weight) | 				if ( WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]) ) | ||||||
| 					ereport(ERROR, | 					ereport(ERROR, | ||||||
| 							(errcode(ERRCODE_SYNTAX_ERROR), | 							(errcode(ERRCODE_SYNTAX_ERROR), | ||||||
| 							 errmsg("syntax error"))); | 							 errmsg("syntax error"))); | ||||||
| 				state->pos[*(uint16 *) (state->pos)].weight = 0; | 				WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 0 ); | ||||||
| 			} | 			} | ||||||
| 			else if (isspace((unsigned char) *(state->prsbuf)) || | 			else if (isspace((unsigned char) *(state->prsbuf)) || | ||||||
| 					 *(state->prsbuf) == '\0') | 					 *(state->prsbuf) == '\0') | ||||||
| @ -540,9 +539,9 @@ tsvector_out(PG_FUNCTION_ARGS) | |||||||
| 			wptr = POSDATAPTR(out, ptr); | 			wptr = POSDATAPTR(out, ptr); | ||||||
| 			while (pp) | 			while (pp) | ||||||
| 			{ | 			{ | ||||||
| 				sprintf(curout, "%d", wptr->pos); | 				sprintf(curout, "%d", WEP_GETPOS(*wptr)); | ||||||
| 				curout = strchr(curout, '\0'); | 				curout = strchr(curout, '\0'); | ||||||
| 				switch (wptr->weight) | 				switch (WEP_GETWEIGHT(*wptr)) | ||||||
| 				{ | 				{ | ||||||
| 					case 3: | 					case 3: | ||||||
| 						*curout++ = 'A'; | 						*curout++ = 'A'; | ||||||
| @ -704,8 +703,8 @@ makevalue(PRSTEXT * prs) | |||||||
| 			wptr = POSDATAPTR(in, ptr); | 			wptr = POSDATAPTR(in, ptr); | ||||||
| 			for (j = 0; j < *(uint16 *) cur; j++) | 			for (j = 0; j < *(uint16 *) cur; j++) | ||||||
| 			{ | 			{ | ||||||
| 				wptr[j].weight = 0; | 				WEP_SETWEIGHT(wptr[j], 0); | ||||||
| 				wptr[j].pos = prs->words[i].pos.apos[j + 1]; | 				WEP_SETPOS(wptr[j], prs->words[i].pos.apos[j + 1]); | ||||||
| 			} | 			} | ||||||
| 			cur += sizeof(uint16) + prs->words[i].pos.apos[0] * sizeof(WordEntryPos); | 			cur += sizeof(uint16) + prs->words[i].pos.apos[0] * sizeof(WordEntryPos); | ||||||
| 			pfree(prs->words[i].pos.apos); | 			pfree(prs->words[i].pos.apos); | ||||||
|  | |||||||
| @ -23,6 +23,8 @@ typedef struct | |||||||
| #define MAXSTRLEN ( 1<<11 ) | #define MAXSTRLEN ( 1<<11 ) | ||||||
| #define MAXSTRPOS ( 1<<20 ) | #define MAXSTRPOS ( 1<<20 ) | ||||||
| 
 | 
 | ||||||
|  | /*
 | ||||||
|  | Equivalent to  | ||||||
| typedef struct | typedef struct | ||||||
| { | { | ||||||
|        uint16 |        uint16 | ||||||
| @ -30,6 +32,17 @@ typedef struct | |||||||
|                                 pos:14; |                                 pos:14; | ||||||
| }       WordEntryPos; | }       WordEntryPos; | ||||||
| 
 | 
 | ||||||
|  | */ | ||||||
|  | 
 | ||||||
|  | typedef uint16 WordEntryPos; | ||||||
|  | 
 | ||||||
|  | #define  WEP_GETWEIGHT(x)	( (x) >> 14 ) | ||||||
|  | #define  WEP_GETPOS(x)	( (x) & 0x3fff ) | ||||||
|  | 
 | ||||||
|  | #define  WEP_SETWEIGHT(x,v)  (x) = ( (v) << 14 ) | ( (x) & 0x3fff )  | ||||||
|  | #define  WEP_SETPOS(x,v)	(x) = ( (x) & 0xc000 ) | ( (v) & 0x3fff )  | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| #define MAXENTRYPOS (1<<14) | #define MAXENTRYPOS (1<<14) | ||||||
| #define MAXNUMPOS	256 | #define MAXNUMPOS	256 | ||||||
| #define LIMITPOS(x) ( ( (x) >= MAXENTRYPOS ) ? (MAXENTRYPOS-1) : (x) ) | #define LIMITPOS(x) ( ( (x) >= MAXENTRYPOS ) ? (MAXENTRYPOS-1) : (x) ) | ||||||
|  | |||||||
| @ -106,7 +106,7 @@ setweight(PG_FUNCTION_ARGS) | |||||||
| 			p = POSDATAPTR(out, entry); | 			p = POSDATAPTR(out, entry); | ||||||
| 			while (j--) | 			while (j--) | ||||||
| 			{ | 			{ | ||||||
| 				p->weight = w; | 				WEP_SETWEIGHT(*p,w); | ||||||
| 				p++; | 				p++; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @ -144,10 +144,10 @@ add_pos(tsvector * src, WordEntry * srcptr, tsvector * dest, WordEntry * destptr | |||||||
| 		*clen = 0; | 		*clen = 0; | ||||||
| 
 | 
 | ||||||
| 	startlen = *clen; | 	startlen = *clen; | ||||||
| 	for (i = 0; i < slen && *clen < MAXNUMPOS && (*clen == 0 || dpos[*clen - 1].pos != MAXENTRYPOS - 1); i++) | 	for (i = 0; i < slen && *clen < MAXNUMPOS && (*clen == 0 || WEP_GETPOS(dpos[*clen - 1]) != MAXENTRYPOS - 1); i++) | ||||||
| 	{ | 	{ | ||||||
| 		dpos[*clen].weight = spos[i].weight; | 		WEP_SETWEIGHT(dpos[*clen], WEP_GETWEIGHT(spos[i])); | ||||||
| 		dpos[*clen].pos = LIMITPOS(spos[i].pos + maxpos); | 		WEP_SETPOS(dpos[*clen], LIMITPOS(WEP_GETPOS(spos[i]) + maxpos)); | ||||||
| 		(*clen)++; | 		(*clen)++; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -186,8 +186,8 @@ concat(PG_FUNCTION_ARGS) | |||||||
| 			p = POSDATAPTR(in1, ptr); | 			p = POSDATAPTR(in1, ptr); | ||||||
| 			while (j--) | 			while (j--) | ||||||
| 			{ | 			{ | ||||||
| 				if (p->pos > maxpos) | 				if (WEP_GETPOS(*p) > maxpos) | ||||||
| 					maxpos = p->pos; | 					maxpos = WEP_GETPOS(*p); | ||||||
| 				p++; | 				p++; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user