Skip to content

Commit 6ed35e2

Browse files
committed
Adding multiple INDEX fields
1 parent 25cbf98 commit 6ed35e2

File tree

10 files changed

+119
-67
lines changed

10 files changed

+119
-67
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,8 @@ the documentation and product header files claim.
5959
* Some SMF integers are too large for the INTEGER datatype. The unsigned
6060
32-bits compared to the SQL which is signed 32-bit, So switching
6161
to always use BIGINT.
62+
63+
Mar 2018
64+
* Add code to help add INDEX to columns in the SQL DDL output
65+
* Add optimisation to Makefiles
66+
* Even 64-bit values may be too large when they are not really counters

bin/aix/convH

0 Bytes
Binary file not shown.

bin/aix/mqsmfcsv

-50.4 KB
Binary file not shown.

bin/linux/mqsmfcsv

46 KB
Binary file not shown.

bin/win/mqsmfcsv.exe

-226 KB
Binary file not shown.

src/M

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plat=`uname`
44

55
if [ "$plat" = "AIX" ]
66
then
7-
flags="-q32"
7+
flags="-q32 -qmaxmem=-1"
88
cc="xlc"
99
targdir="../bin/aix"
1010
else
@@ -15,6 +15,8 @@ fi
1515
if [ "$CCDEBUG" != "" ]
1616
then
1717
flags="$flags -g"
18+
else
19+
flags="$flags -O"
1820
fi
1921

2022
export PLATFLAGS=$flags CC=$cc VERS=904

src/Makefile.win

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
1-
CFLAGS=-nologo /D_CRT_SECURE_NO_WARNINGS /Zp1 /J
2-
VERS=904
3-
SRC = mqsmf.c \
4-
smfDDL.c \
5-
smfDate.c \
6-
smfConv.c \
7-
printDEBUG.c \
8-
printQ5ST.c \
9-
printQCST.c \
10-
printQCCT.c \
11-
printQCTADP.c\
12-
printQCTDNS.c\
13-
printQCTDSP.c\
14-
printQCTSSL.c\
15-
printQESD.c \
16-
printQEST.c \
17-
printQIS1.c \
18-
printQIST.c \
19-
printQJST.c \
20-
printQLST.c \
21-
printQMAC.c \
22-
printQMST.c \
23-
printQPST.c \
24-
printQSGM.c \
25-
printQSPH.c \
26-
printQSRS.c \
27-
printQSST.c \
28-
printQTST.c \
29-
printWQ.c \
30-
printWTAS.c \
31-
printWTID.c
32-
33-
HDR = mqsmfstruc.h \
34-
mqsmf.h
35-
36-
mqsmfcsv.exe: $(SRC) $(HDR) Makefile.win
37-
rm -f $@
38-
$(CC) $(SRC) -I. /Fe$@ $(CFLAGS) -DCSQDSMF_VERSION=$(VERS)
39-
del /q *.obj
40-
copy $@ ..\bin\win
41-
42-
mqsmfstruc.h: csqdsmfc-$(VERS).h convH.exe dummy
43-
convH < csqdsmfc-$(VERS).h > $@
44-
45-
convH.exe: convH.c
46-
$(CC) /Fe$@ convH.c
47-
copy $@ ..\bin\win
48-
49-
50-
dummy:
51-
1+
CFLAGS=-nologo /D_CRT_SECURE_NO_WARNINGS /Zp1 /J /O2
2+
VERS=904
3+
SRC = mqsmf.c \
4+
smfDDL.c \
5+
smfDate.c \
6+
smfConv.c \
7+
printDEBUG.c \
8+
printQ5ST.c \
9+
printQCST.c \
10+
printQCCT.c \
11+
printQCTADP.c\
12+
printQCTDNS.c\
13+
printQCTDSP.c\
14+
printQCTSSL.c\
15+
printQESD.c \
16+
printQEST.c \
17+
printQIS1.c \
18+
printQIST.c \
19+
printQJST.c \
20+
printQLST.c \
21+
printQMAC.c \
22+
printQMST.c \
23+
printQPST.c \
24+
printQSGM.c \
25+
printQSPH.c \
26+
printQSRS.c \
27+
printQSST.c \
28+
printQTST.c \
29+
printWQ.c \
30+
printWTAS.c \
31+
printWTID.c
32+
33+
HDR = mqsmfstruc.h \
34+
mqsmf.h
35+
36+
mqsmfcsv.exe: $(SRC) $(HDR) Makefile.win
37+
rm -f $@
38+
$(CC) $(SRC) -I. /Fe$@ $(CFLAGS) -DCSQDSMF_VERSION=$(VERS)
39+
del /q *.obj
40+
copy $@ ..\bin\win
41+
42+
mqsmfstruc.h: csqdsmfc-$(VERS).h convH.exe dummy
43+
convH < csqdsmfc-$(VERS).h > $@
44+
45+
convH.exe: convH.c
46+
$(CC) /Fe$@ convH.c
47+
copy $@ ..\bin\win
48+
49+
50+
dummy:
51+

src/mqsmf.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ extern void printWTID (wtid *, unsigned char *);
154154
extern void openDDL (char *);
155155
extern void closeDDL (char *);
156156
extern void printDDL (char *,int, int);
157-
extern void setIndex (char *);
157+
extern void addIndex (char *);
158158

159159

160160
/*******************************************************/
@@ -221,6 +221,16 @@ extern char *strCfStatType (int v);
221221
#define DDL_SUS (4)
222222
#define DDL_DATETIME (5)
223223

224+
/************************************************************************/
225+
/* Some "unsigned 64-bit" in the SMF are really pointers or correlators */
226+
/* No real counter is likely to reach the top bit. But treating them as */
227+
/* unsigned values in these cases is causing overflow when loading into */
228+
/* DB2 because SQL 64-bit quantities are always signed with no option */
229+
/* for the C datatype. So as an expediency, we will drop the sign bit */
230+
/* which should not affect any real calculations. */
231+
/************************************************************************/
232+
#define DROPSIGN 0x7FFFFFFFFFFFFFFF
233+
224234
/**********************************************************/
225235
/* Macros to build the printable lines for CSV output. */
226236
/* Separate macros for each data type and when we need */
@@ -265,7 +275,7 @@ extern char *strCfStatType (int v);
265275

266276
#define ADDU64(h,v) \
267277
ADDHEAD(h,DDL_I64,0); \
268-
ADDDATA("%llu,",conv64(v))
278+
ADDDATA("%lld,",(DROPSIGN & conv64(v)))
269279

270280
#define ADDS64IDX(h,idx,v) \
271281
if (first) sprintf(tmpHead,"%s {%s}",h,idx); \
@@ -275,7 +285,7 @@ extern char *strCfStatType (int v);
275285
#define ADDU64IDX(h,idx,v) \
276286
if (first) sprintf(tmpHead,"%s {%s}",h,idx); \
277287
ADDHEAD(tmpHead,DDL_I64,0); \
278-
ADDDATA("%llu,",conv64(v))
288+
ADDDATA("%lld,",(DROPSIGN & conv64(v)))
279289

280290
#define ADDS32(h,v) \
281291
ADDHEAD(h,DDL_I,0); \
@@ -395,6 +405,11 @@ extern char *strCfStatType (int v);
395405
} \
396406
COMMON_BLOCK
397407

408+
#define ADDINDEX(n) \
409+
if (first) { \
410+
addIndex(n); \
411+
}
412+
398413
#define SMFPRINTSTOP \
399414
if (first && newFile && printHeaders) \
400415
{ \

src/printWQ.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void printWQ(wq *p)
3838
ADDSTRB ("Correlation" ,p->correl, 16);
3939
ADDSTREN("Open_Name",p->objname,48);
4040
ADDSTREN("Base_Name",p->basename,48);
41-
setIndex("Base_Name");
41+
ADDINDEX("Base_Name");
4242
ADDTIME ("Open" ,p->opentime);
4343
ADDTIME ("Close" ,p->clostime);
4444

src/smfDDL.c

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,79 @@
1717

1818
static FILE *fp = NULL;
1919
char *comma = "";
20+
char *schema = "MQSMF";
2021

21-
char *primaryKey = NULL;
22+
#define INDEXSETSIZE 128
23+
char *indexSet[INDEXSETSIZE] = {0};
24+
int nextIndex = 0;
2225

2326
#define COL_HEAD_LEN (64)
2427

2528
static char *format(char *);
2629

30+
/*
31+
* The DDL generated here is very simple. The
32+
* table is created with a fixed name and relevant
33+
* datatypes. If any index columns have been named
34+
* then those are added to the DDL with each table.
35+
* There is no "Primary key" defined.
36+
*/
37+
2738
void openDDL(char *name)
2839
{
2940
BOOL newFile;
41+
int i;
42+
43+
for (i=0;i<INDEXSETSIZE;i++)
44+
{
45+
indexSet[i] = NULL;
46+
}
47+
nextIndex = 0;
3048

31-
primaryKey = NULL;
3249
if (!fp)
3350
{
3451
fp = fopenext("MQTABLES","ddl", &newFile);
3552
if (!fp) /* fopenext will print detailed error message */
3653
exit(1);
3754
}
38-
fprintf(fp,"DROP TABLE MQSMF.%s; \n",name);
55+
fprintf(fp,"DROP TABLE %s.%s; \n",schema,name);
3956

4057
/* If you want more sophisticated SQL, then you could change this */
41-
fprintf(fp,"CREATE TABLE MQSMF.%s (\n",name);
58+
fprintf(fp,"CREATE TABLE %s.%s (\n",schema,name);
4259
comma = " "; /* Start with it blank */
4360
}
4461

4562
void closeDDL(char *name)
4663
{
64+
int i;
4765
if (fp)
4866
{
67+
/* Could add "... IN <tablespace>" to this if needed */
4968
fprintf(fp,");\n");
50-
if (primaryKey) {
51-
fprintf(fp,"CREATE INDEX %s ON MQSMF.%s(%s);\n",primaryKey,name,primaryKey);
69+
for (i=0;i<INDEXSETSIZE;i++)
70+
{
71+
char *c = indexSet[i];
72+
if (c) {
73+
fprintf(fp,"CREATE INDEX %s ON %s.%s(%s);\n",c,schema,name,c);
74+
}
5275
}
5376
fprintf(fp,"\n");
5477
fflush(fp);
5578
}
5679
return;
5780
}
5881

59-
void setIndex(char *key)
82+
void addIndex(char *key)
6083
{
61-
primaryKey = key;
84+
if (nextIndex <INDEXSETSIZE) {
85+
indexSet[nextIndex] = key;
86+
nextIndex++;
87+
}
88+
else
89+
{
90+
/* Extremely unlikely that we'll have this number of index columns for a table */
91+
printf("Warning: Cannot add %s to table index. Need to increase INDEXSETSIZE\n",key);
92+
}
6293
return;
6394
}
6495

@@ -94,11 +125,10 @@ void printDDL(char *name, int type, int len)
94125
fprintf(fp,"%s %s \t CHAR(%d)\n",comma,format(nameCopy),len);
95126
}
96127
break;
97-
case DDL_SUS:
128+
case DDL_SUS: /* a seconds/microseconds field */
98129
p2 = strstr(nameCopy,"(US)");
99130
if (p2) *p2 = 0;
100131
fprintf(fp,"%s %s_us \t BIGINT\n",comma,format(nameCopy));
101-
102132
break;
103133

104134
case DDL_DATETIME:
@@ -181,7 +211,7 @@ static char *format(char *name)
181211

182212
/* Check for column name length - I've seen this as a limit in some DBs */
183213
/* Leave room for _DATE etc as prefix */
184-
if(strlen(nameNoDup) > 27)
214+
if (strlen(nameNoDup) > 27)
185215
printf("Warning: Column %s may be too long\n",nameNoDup);
186216

187217
return nameNoDup;

0 commit comments

Comments
 (0)